Add write service to system_log (#9214)

This commit is contained in:
Mika Hiltunen 2019-04-16 10:17:56 +03:00 committed by Fabian Affolter
parent 6226761fc3
commit 8c9e54a425

View File

@ -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 %}