diff options
author | root <root@smartpi.suren.me> | 2023-01-10 07:45:02 +0400 |
---|---|---|
committer | root <root@smartpi.suren.me> | 2023-01-10 07:45:02 +0400 |
commit | 2c0c331eb7b7a03152309bbbd4e0fee157e8d86c (patch) | |
tree | 03391160212b39c4597ecc26010f2ba1235a65e3 /python_scripts | |
download | hass-2c0c331eb7b7a03152309bbbd4e0fee157e8d86c.tar.gz hass-2c0c331eb7b7a03152309bbbd4e0fee157e8d86c.tar.bz2 hass-2c0c331eb7b7a03152309bbbd4e0fee157e8d86c.tar.xz hass-2c0c331eb7b7a03152309bbbd4e0fee157e8d86c.zip |
Initial configuration
Diffstat (limited to 'python_scripts')
-rw-r--r-- | python_scripts/set_state.py | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/python_scripts/set_state.py b/python_scripts/set_state.py new file mode 100644 index 0000000..fae5c7c --- /dev/null +++ b/python_scripts/set_state.py @@ -0,0 +1,27 @@ +#================================================================================================== +# python_scripts/set_state.py +#================================================================================================== + +#-------------------------------------------------------------------------------------------------- +# Set the state or other attributes for the entity specified in the Automation Action +#-------------------------------------------------------------------------------------------------- + +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) |