-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathmotion_detector_set_state.py
25 lines (22 loc) · 1.1 KB
/
motion_detector_set_state.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
#==================================================================================================
# Save in python_scripts/set_state.py
# Set the state or other attributes for the entity specified in the Automation Action
# more info here: https://github.com/xannor/hass_py_set_state
#==================================================================================================
inputEntity = data.get('entity_id')
if inputEntity is None:
logger.warning("===== entity_id is required if you want to set something.")
else:
inputStateObject = hass.states.get(inputEntity)
inputState = inputStateObject.state
inputAttributesObject = inputStateObject.attributes.copy()
for item in data:
newAttribute = data.get(item)
logger.debug("===== item = {0}; value = {1}".format(item,newAttribute))
if item == 'entity_id':
continue # already handled
elif item == 'state':
inputState = newAttribute
else:
inputAttributesObject[item] = newAttribute
hass.states.set(inputEntity, inputState, inputAttributesObject)