AppDaemon set_state automation issue

Hi there
I have some groups and subgroups of lights that I can control, in addition to each light individually, however this groups aren’t HA groups.

The groups are configured in the lights hub because in an HA group it will trigger each light of that group which have a noticeable delay unlike the light hub that broadcast the command turning on/off all the lights instantaneous.

So, for HA the groups are just a simple MQTT light.

Now, I tried to create a python script in AppDaemon to sync the lights states in HA, I mean, if I turn on the lights of one group, I want to change the state to “on” of each subgroup of that group and each individual light. I wanted to make use of set_state to change just the internal state in HA without triggering the command to change the lights.

However, this is getting a behavior that I was not expecting:
HA_AppDaemon_automation

When I trigger the group (Living Room Back), as excepted, the script is executed and change the state of the 2 subgroups (Living Room FB and B) but then I cannot change that subgroups internal HA state again although the actual lights change the state.
If I turn off the group, the subgroups turn off also and everything seams ti work again.

The script for now is just this:

import appdaemon.plugins.hass.hassapi as hass

class LivingRoomLightsSync(hass.Hass):

  def initialize(self):
     self.listen_state(self.state_change, "light.living_room_back")

  def state_change(self, entity, attribute, old, new, kwargs):
     self.set_state("light.living_room_fb", state=new)
     self.set_state("light.living_room_b", state=new)

Just some aditional information:

  • In AppDaemon HADashboard this seams to work as expected.
  • I’ve Hass.io installed with the version 1.31, with the previous version the behavior was the same
  • I’ve this lights configured as MQTT lights

I thank you in advance for all the help you can give me.

set_state is really problematic in a lot of cases when it goes for existing entities.

i would advice you just use turn_on and turn_off.

the lights will get turned on or off twice but a light that is on and gets turned on will just stay on.

1 Like

Hey Rene, thank you for your reply.

Well, that’s not ideal but if I don’t have any other option… Maybe I open a bug in github for this but for what I’m seeing, this set_state is more for development purposes but can always try and hope.

Thanks again.

i assure you that its not a bug in AD.
its how HA is designed.

Yes, I thought soo, because in HADashboard it works flawlessly. But maybe in Home-Assistant side… but if you are telling that is that by design, probably will not be that easy.

if it works as expected in dashboard, then it should also work as expected in the HA frontend.
in that case you need to use what i told, self.turn_on and self.turn_off instead of set state.

because thats exactly what the dashboard does.