Is it possible to update other entities states.
The case I’m looking at is:
I have a component to manage my blinds (see yaml). The commands are RF commands, so I prefer to just send 1 for each task, not group them together which would result in multiple commands.
Edit: Based on some research track_state_changes seems like a good option. This is where I’m up to:
covers:
blockout_blinds:
friendly_name: blockout
command_stop: ...
command_open: ...
command_close: ...
sunshade_blinds:
friendly_name: sunshade
command_stop: ...
command_open: ...
command_close: ...
all_blinds:
friendly_name: all
command_stop: ...
command_open: ...
command_close: ...
What I want to configure is when all_blinds does a command it updates the state of sunshade and blockout, ideally configurable like:
blockout_blinds:
friendly_name: all
command_stop: ...
command_open: ...
command_close: ...
covers_list:
- cover.all_blinds
Component snippet
track_state_change(hass, self._covers_watch, self.covers_state_changed)
For anyone who’s looking this up, this is how I achieved it:
from homeassistant.helpers.event import track_state_change
...
track_state_change(hass, self._covers_list, self.covers_state_changed)
...
def covers_state_changed(self, entity_id, from_state, to_state):
try:
_LOGGER.debug(entity_id + " change from " + str(from_state) + " to " + str(to_state))
if to_state.attributes.get(ATTR_CURRENT_POSITION) != self.tc.current_position():
_LOGGER.debug(self.entity_id + ' changed position from ' + str(self.tc.current_position()) + ' to ' + str(to_state.attributes.get(ATTR_CURRENT_POSITION)))
self.tc.set_position(to_state.attributes.get(ATTR_CURRENT_POSITION))
self.schedule_update_ha_state()
except:
pass