/docs/MyDocs

To get this branch, use:
bzr branch http://darksoft.org/webbzr/docs/MyDocs

« back to all changes in this revision

Viewing changes to Administration/SmartHome/Hass/04_concepts.txt

  • Committer: Suren A. Chilingaryan
  • Date: 2022-06-20 03:20:18 UTC
  • Revision ID: csa@suren.me-20220620032018-xquk369l0ukymgaa
Home Assistant

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
Terminology
 
2
===========
 
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)
 
10
 
 
11
Variables
 
12
=========
 
13
 Context-specific
 
14
 ----------------
 
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')
 
26
 Global
 
27
 ------
 
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
 
33
    device
 
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
 
38
    area
 
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
 
42
 
 
43
 
 
44
Events
 
45
======
 
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
 
48
    automation_triggered
 
49
    script_started
 
50
 
 
51
 
 
52
Automation:                                                     - Trigger (events or state-changes), Condition (states), Action (services). 
 
53
==========                                                      Templates to get properties from trigger event and use it for parametrization.
 
54
  automation:
 
55
    trigger_variables:                                          - Set some global variable which can be used in templates
 
56
        room: "living_room"
 
57
        node: "ac"
 
58
  
 
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
 
62
 
 
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)
 
67
        enabled: false
 
68
        event_type: "custom_event"                              - Triggers if single event is processed
 
69
        event_type:                                             - Triggers if any of events is processed
 
70
            - custom_event1
 
71
            - custom_event2
 
72
        event_data:                                             - Triggers only if specific data is associated with event
 
73
            state: "on"
 
74
        context:
 
75
               user_id: ...
 
76
 
 
77
      - platform: homeassistant
 
78
        event: start | shutdown
 
79
 
 
80
      - platform: mqtt          
 
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"
 
85
        encoding: "utf-8"
 
86
        
 
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.
 
92
        below: ##
 
93
        for: "00:00:30"                                         - Triggers only if condition has been true for the specified time
 
94
 
 
95
      - platform: numeric_state                                 - Triggers when it is dark outside
 
96
        entity_id: sun.sun
 
97
        attribute: elevation
 
98
        below: -4.0
 
99
 
 
100
      - platform: state                                         
 
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
 
104
 
 
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
 
107
 
 
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
 
110
 
 
111
        from: "off"                                             - Exactly changes from 'off' to 'on'
 
112
        to: "on"                                                
 
113
 
 
114
        not_from: "on"
 
115
        not_to: "off"
 
116
 
 
117
      - platform: tag
 
118
        tag_id: A7-6B-90-5F                                     - Triggers when NFC tag scanned
 
119
        device_id: 0e19cd3cf2b311ea88f469a7512c307d             .. By a specific device
 
120
 
 
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)
 
124
 
 
125
      - platform: time
 
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 ]
 
127
 
 
128
      - platform: time_pattern
 
129
        hours|minutes: 5 | /5                                   - Cron. Triggered at xx:05 or every 5 minutes
 
130
 
 
131
      - platform: calendar                                      - Triggers when the specified event in calendar starts or ends
 
132
        event: start | end
 
133
        entity_id: calendar.light_schedule
 
134
 
 
135
      - platform: zone                                          - Location based triggers
 
136
        entity_id: person.paulus
 
137
        zone: zone.home
 
138
        event: enter | leave
 
139
 
 
140
      - platform: webhook
 
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")
 
144
        
 
145
  condition:                                                    - Additional Checks
 
146
    - or | and:
 
147
      - condition: numeric_state | ... (see triggers)
 
148
        attribute: elevation
 
149
        below: 4
 
150
      - condition: "{{ state_attr('sun.sun', 'elevation') < 4 }}"
 
151
      - ...
 
152
 
 
153
  action:                                                       - See script syntax for details, here few samples only
 
154
    - service: light.turn_on
 
155
      target:
 
156
        entity_id: light.kitchen                                - also lists are supported
 
157
      data:
 
158
        brightness: 150
 
159
        rgb_color: [255, 0, 0]
 
160
 
 
161
    - condition: "{{ }}"                                        - follwoing actions skipped if condition is not true (also could be a list of conditions)
 
162
 
 
163
    - service: scene.turn_on                                    - enable specified scene
 
164
      target:
 
165
        entity_id: scene.romantic                               - Instead of ID, the scene definition could go bellow
 
166
 
 
167
    - conditions: [ ]                                           - multiple conditions should match
 
168
 
 
169
 
 
170
Scenes                                                          - Defines a whole set of entities along with state and attributes
 
171
======
 
172
 scene:
 
173
  - name: Movies                                                - One scene defined
 
174
    entities:
 
175
      light.ceiling: "off"
 
176
      light.tv_back_light:
 
177
        state: "on"
 
178
        brightness: 125
 
179
      media_player.sony_bravia_tv:
 
180
        state: "on"
 
181
        source: HDMI 1
 
182
  - name: Standard                                              - Another
 
183
    entities:
 
184
      light.tv_back_light:
 
185
        state: "off"
 
186
      light.ceiling:
 
187
        state: "on"
 
188
        brightness: 125
 
189
        color_mode: "white"
 
190