Last active
January 30, 2024 08:24
-
-
Save pelrun/91feae869aa9bfe9faa610a1fbbee9b3 to your computer and use it in GitHub Desktop.
Home Assistant script to set an entity's state, used with the IKEA Tradfri remote control.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
if 'entity_id' not in data: | |
logger.warning("===== entity_id is required if you want to set something.") | |
else: | |
data = data.copy() | |
inputEntity = data.pop('entity_id') | |
inputStateObject = hass.states.get(inputEntity) | |
if inputStateObject: | |
inputState = inputStateObject.state | |
inputAttributesObject = inputStateObject.attributes.copy() | |
else: | |
inputState = 'unknown' | |
inputAttributesObject = {} | |
if 'state' in data: | |
inputState = data.pop('state') | |
logger.debug("===== new attrs: {}".format(data)) | |
inputAttributesObject.update(data) | |
hass.states.set(inputEntity, inputState, inputAttributesObject) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I.e If you set the state in Dev Tools it reverts automatically? In this case, nothing can be done to override the constant and continual state updating that HA/componets inherently do.