Skip to content

Log message to view in Home Assistant from a external system

Notifications You must be signed in to change notification settings

kgn3400/message_log

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

40 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Message log

GitHub release (latest by date) GitHub all releases GitHub last commit GitHub code size in bytes Validate% with hassfest

The Message log integration allows you to log and view logged messages in Home Assistant added from a external system. Message can be created as info, attention, warning or error.

For installation instructions until the Message log integrations is part of HACS, see this guide. Or click My Home Assistant

Open your Home Assistant instance and start setting up a new integration.

Configuration

Configuration is setup via UI in Home assistant. To add one, go to Settings > Devices & Services and click the add button. Next choose the Message log option.

Services

Available services: add, order_by, remove_message and show_message

Adding messages from an external system

Below is an example of how to add a message from an external system written in Python.

class MessageLevels(Enum):
    """Message levels."""

    INFO = 10
    ATTENTION = 20
    WARNING = 30
    ERROR = 40

def message_to_hass_log(
    message: str,
    message_level: MessageLevels | None = None,
    icon: str | None = None,
    remove_after: float | None = None,
    notify: bool | None = None,
    added_at: datetime | None = None,
) -> None:
    """Message to hass."""

    headers = {
        "Authorization": f"Bearer {HASS_TOKEN}",
        "content-type": "application/json",
    }
    data: dict[str, Any] = {"message": message}

    if message_level is not None:
        data["message_level"] = message_level.name

    if icon is not None:
        data["icon"] = icon

    if remove_after is not None:
        data["remove_after"] = remove_after

    if notify:
        data["notify"] = notify

    if added_at:
        data["added_at"] = added_at.strftime("%Y-%m-%d %H:%M:%S")

    post(URL, headers=headers, json=data, timeout=3)