From 8c9e54a4257102a11c8be1caeeae237d1d547d0f Mon Sep 17 00:00:00 2001 From: Mika Hiltunen Date: Tue, 16 Apr 2019 10:17:56 +0300 Subject: [PATCH] Add write service to system_log (#9214) --- source/_components/system_log.markdown | 31 ++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/source/_components/system_log.markdown b/source/_components/system_log.markdown index b8d77fd378c..2f0befb2c99 100644 --- a/source/_components/system_log.markdown +++ b/source/_components/system_log.markdown @@ -43,6 +43,16 @@ fire_event: To manually clear the system log, call this service. +### {% linkable_title Service `write` %} + +Write a log entry + +| Service data attribute | Optional | Description | +| ---------------------- | -------- | ------------------------------------------------------------------------------- | +| `message` | no | Message to log | +| `level` | yes | Log level: debug, info, warning, error, critical. Defaults to 'error'. | +| `logger` | yes | Logger name under which to log the message. Defaults to 'system_log.external'. | + ## {% linkable_title Events %} Errors and warnings are posted as the event `system_log_event`, so it is possible to write automations that trigger whenever a warning or error occurs. The following information is included in each event: @@ -114,3 +124,24 @@ automation: message: '{{ trigger.event.data.message }}' ``` {% endraw %} + +### {% linkable_title Writing to log %} + +This automation will create a new log entry when the door is opened: + +{% raw %} +```yaml +automation: + - alias: Log door opened + trigger: + platform: state + entity_id: binary_sensor.door + from: 'off' + to: 'on' + action: + service: system_log.write + message: 'Door opened!' + level: info +``` +{% endraw %} +