@@ -136,8 +136,39 @@ an attribute that doesn't exist will throw a ``AttributeError`` exception. One e
136
136
to this that in a ``@state_trigger `` expression, undefined state variables will evaluate to
137
137
``None `` instead of throwing an exception.
138
138
139
- Two virtual attribute values are available when you use a variable directly as ``DOMAIN.entity.attr ``
140
- or call ``state.get("DOMAIN.entity.attr") ``:
139
+ State variables also support virtual methods that are service calls with that ``entity_id ``.
140
+ For any state variable ``DOMAIN.ENTITY ``, any services registered by ``DOMAIN ``, eg:
141
+ ``DOMAIN.SERVICE ``, that have an ``entity_id `` parameter can be called as a method
142
+ ``DOMAIN.ENTITY.SERVICE() ``. Each of these statements are equivalent:
143
+
144
+ .. code :: python
145
+
146
+ service.call(" DOMAIN" , " SERVICE" , entity_id = " DOMAIN.ENTITY" , other_param = 123 )
147
+ DOMAIN .SERVICE(entity_id = " DOMAIN.ENTITY" , other_param = 123 )
148
+ DOMAIN .ENTITY .SERVICE(other_param = 123 )
149
+
150
+ In the case the service has only one other parameter in addition to ``entity_id ``, a further
151
+ shorthand is that the method can be called with just a positional, rather than keyword parameter.
152
+ So if the service only takes two parameters, ``entity_id `` and ``other_param ``, this additional
153
+ form is equivalent to each of the above statements:
154
+
155
+ .. code :: python
156
+
157
+ DOMAIN .ENTITY .SERVICE(123 )
158
+
159
+ Here's an example using ``input_number ``, assuming it has been configured to create an entity
160
+ ``input_number.test ``. These statements all do the same thing (and the last one works because
161
+ ``set_value `` only takes on other parameter):
162
+
163
+ .. code :: python
164
+
165
+ service.call(" input_number" , " set_value" , entity_id = " input_number.test" , value = 13 )
166
+ input_number.set_value(entity_id = " input_number.test" , value = 13 )
167
+ input_number.test.set_value(value = 13 )
168
+ input_number.test.set_value(13 )
169
+
170
+ Two additional virtual attribute values are available when you use a variable directly as
171
+ ``DOMAIN.entity.attr `` or call ``state.get("DOMAIN.entity.attr") ``:
141
172
142
173
- ``last_changed `` is the last UTC time the state value was changed (not the attributes)
143
174
- ``last_updated `` is the last UTC time the state entity was updated
0 commit comments