3
Devices - Some physical device, basically integration (driver) instance.
4
Entities - Device components (e.g. specific buttons on light switch, temperature and humidity sensors in weather station, etc.). Entities expose services which can be called, e.g. turn_on/turn_off for smartbulbs.
5
Entity defined by its id which has the following format: "<domain>.<device_uid>_<entity>", e.g. switch.0x5c0272fffee160ef_right, sensor.0x00158d0006c667fa_pressure, light.yeelight_color_0x7caaf86
6
Also other components are exposed as entities, e.g. 'automation', 'zone', etc.
7
Domain - Type of entity, e.g. switch, light, sensor, etc.
8
Object/Area - Kitchen, hall, bedroom, ...
9
States - Each entity has a state (and a number of attributes). State machine associated with entities. Changes to state machine is not propogated to devices (and will be overwritten if device is polled)
15
trigger - Trigger causing current code to run
16
{.id, .idx, .platform, .entity_id} - Most of triggers
17
{ .event, .event_type, .event.data} - Event/device/entity triggers
18
{.topic, .payload, .payload_json, .qos) - MQTT triggers
19
{.from_state, .to_state, .for, .bellow, .above } - Numeric/State
20
this - State object of entity
21
{.state, .domain, .entity_id, .object_id} .object_id=<object> (e.g. kitchen), .entity_id=<domain>.<object_id> (e.g. 'light.kitchen')
22
{.last_updated, .last_changed}
23
{.context} {.context_id, .user_id, .parent_id} Unique identifier of context and parent context + user started the change (or None if automatic)
24
{.attributes} {.friendly_name, .icon, .entity_picture, .assumed_state, .unit_of_measurement, ... entity specific attributes ...} assumed_state=boolean (i.e. only approximation, no precise information)
25
state_attr('sensor.livingroom', 'Battery numeric') Accessing custom attributes with space in the attribute name (otherwise 'this.attributes.friendly_name')
28
states.<domain>.<device_uid>_<entity> {.state, ...} - See state object above.
29
states('sensor.0x00158d0006c667fa_pressure') - The '.state' property is better access this way (no error if not set)
30
state_attr('sensor.0x00158d0006c667fa_pressure', '.friendly_name')
31
is_state('entity', 'state') - Checks if entity is in specified state
32
is_state_attr('entity', 'attr', 'value') - Checks if attribute is set to the specified value
34
device_entities(device_id) - returns a list of entities that are associated with a given device ID
35
device_attr(device_or_entity_id, attr_name) - returns the value of attr_name for the given device or entity
36
is_device_attr(device_or_entity_id, attr_name, attr_value)
37
device_id(entity_id) - returns the device ID for a given entity ID or device name
39
area_entities(area_name_or_id) - returns the list of entity IDs tied to a given area ID or name
40
area_devices(area_name_or_id)
41
area_name/area_id(lookup_value) - returns the area name or id for a given device ID, entity ID, or area ID/name
46
call_service - Service is called on the object. E.g. turn_on on the light. Also scripts, or automation (enable scene).
47
state_changed - State in the state machine is changed
52
Automation: - Trigger (events or state-changes), Condition (states), Action (services).
53
========== Templates to get properties from trigger event and use it for parametrization.
55
trigger_variables: - Set some global variable which can be used in templates
59
- mode: single | restart | queued | parallel - What to do if another instance of automation is triggered (cancel new instance, stop current instance, execute both sequentially, or in parallel)
60
max: 25 - Number of queued/parallel instances (defaults to 10)
61
max_exceeded: silent - Level of message to report that too many instances are scheduled in parallel
63
trigger: - Multiple triggers are supported (at least one should fire)
64
- platform: event - Type of trigger. Events are raw building blocks
65
id: "trigger_id" - Referenced from conditions, actions.. Does not need to be unqiue, multiple triggers can be referenced if they share the id.
66
Also multiple ids can be assigned (list)
68
event_type: "custom_event" - Triggers if single event is processed
69
event_type: - Triggers if any of events is processed
72
event_data: - Triggers only if specific data is associated with event
77
- platform: homeassistant
78
event: start | shutdown
81
topic: "hall/switch/ac" - MQTT topic, check e.g. with MQTT Explorer
82
topic: "{{ room ~ '/switch/' ~ node}}" ... Templating example... (Variables defined in 'trigger_variables' section)
83
payload: "on" - Optional. Checks that message payload (receieved on 'hall/switch/ac') is equal to the specified value.
84
value_template: "{{ value_json.state }}" - Used in combination with payload. Checks that message received on 'hall/switch/ac' is valid JSON, with a key 'state'="on"
87
- platform: numeric_state - Fires only once, but will fire again, once the value has left the defined range and enters it again.
88
entity_id: sensor.temperature - Will trigger when 'state' of the entity is changed.
89
attribute: attribute_name - Alternatively (if specified), will trigger when the value of the given attribute for the given entity changes..
90
value_template: "{{ state.attributes.value - 5 }}" - Alternatively (if specified), triggers when the value given by this evaluated template changes.
91
above: ## | sensor.inside_temperature - Numeric value can be specified or another sensor could be referenced.
93
for: "00:00:30" - Triggers only if condition has been true for the specified time
95
- platform: numeric_state - Triggers when it is dark outside
101
entity_id: light.office - By default triggers if state of entity changes or any of associated attributes
102
to: .. (without value) only triggers on state changes
103
for: "00:00:30" .. and the changed state (whatever it is) is unchanged for 30 seconds
105
to: "on" - Triggers if state of light.office changes to "on" (could be also a list)
106
for: "00:00:30" .. and stays "on" for 30 seconds
108
from: "on" - Triggers once state changes to anything else from "on" (should be on first)
109
for: "00:00:30" .. and has not returned to "on" for 30 seconds
111
from: "off" - Exactly changes from 'off' to 'on'
118
tag_id: A7-6B-90-5F - Triggers when NFC tag scanned
119
device_id: 0e19cd3cf2b311ea88f469a7512c307d .. By a specific device
121
- platform: template - Triggers if template evaluates to true
122
value_template: "{% if is_state('device_tracker.paulus', 'home') %}true{% endif %}"
123
for: "00:01:00" .. trigger if template remains true for a hour (polled once per minute, unless refer entity generating events)
126
at: "15:32:00" | sensor.phone_next_alarm - Triggered at specified time which is given or taken from referenced entity [ also accepts a list ]
128
- platform: time_pattern
129
hours|minutes: 5 | /5 - Cron. Triggered at xx:05 or every 5 minutes
131
- platform: calendar - Triggers when the specified event in calendar starts or ends
133
entity_id: calendar.light_schedule
135
- platform: zone - Location based triggers
136
entity_id: person.paulus
141
webhook_id: "hook_id" - curl -X POST -d '{ "key": "value" }' https://smartpi:8123/api/webhook/hook_id (Also PUT/HEAD requests, but not GET)
142
hook_id should be uniq and hook can be used only in a single automation
143
POST data is available in template as {{trigger.json}} or {{trigger.data}} (if JSON is passed, use curl -H "Content-Type: application/json")
145
condition: - Additional Checks
147
- condition: numeric_state | ... (see triggers)
150
- condition: "{{ state_attr('sun.sun', 'elevation') < 4 }}"
153
action: - See script syntax for details, here few samples only
154
- service: light.turn_on
156
entity_id: light.kitchen - also lists are supported
159
rgb_color: [255, 0, 0]
161
- condition: "{{ }}" - follwoing actions skipped if condition is not true (also could be a list of conditions)
163
- service: scene.turn_on - enable specified scene
165
entity_id: scene.romantic - Instead of ID, the scene definition could go bellow
167
- conditions: [ ] - multiple conditions should match
170
Scenes - Defines a whole set of entities along with state and attributes
173
- name: Movies - One scene defined
179
media_player.sony_bravia_tv:
182
- name: Standard - Another