Turn on general switch when trying to turn on unavailable entity

Trying to make my first automations and so on, so sorry if the question is a bit dumb.

Basically I have a smart switch (sonoff mini) on the light switch, but the light is also smart (one of the rectancular philips ones). Connected both on Zigbee fine and can control them fine.

I’m trying to make some automation/script to sync the state of the light and its switch.
I can turn on the light when the switch gets turned on easily. And also turn the switch off when I turn the light off.
But if I try to turn on the light directly, but it’s unavailable because the switch is off, it fails to turn on the swich.

I noticed that it works ONLY if the light has been turned off for 2-3 seconds tops, so my guess it does that because the light itself has enough power to reply to HA.
I figured that the automation triggers not when it receives the command to turn the light on from the GUI, but when it gets the reply from the light that it’s on.

Is there a way to trigger the automation from the gui request to turn it on instead?

Why you always find the solution minutes after asking for help, after trying to find it for hours before asking?

Well, I guess I leave the answer here if anyone needs it:

Can’t do it from Automations (or at least I didn’t find how)
From Scripts use “event” as triggers, type would be “call_service” and then under Event Data something like this:

domain: light
service: turn_on
service_data:
   entity_id: light.yourlightidhere_light

Hopefully it’ll be useful for someone else in the future.

Have a search around the forums. There’s quite a few threads explaining why a smart switch controlling a smart light is a bad idea, especially for zigbee stuff.

If you’re happy with the current workaround you have in place, then fine. However, you could simply rewire the light so that it’s got a permanent live if you’re inclined (simply move the wire leading to your light from L-out to L-in in the module). That should stop the bulb being unavailable, but you’ll have to write an automation to turn on/off the bulb based on the switch module state.

Alternatively, leave the wiring as is and replace your switch module with a switch which supports “decoupled mode”. There’s a couple of threads here explaining that too.

Not sure about decoupled mode, I’ll look into it, but main reason why I have both is that I wired it like this is that (since the light turns itself on if it loses power and then gets it again) I want to be able for everything essential (lights, shutters,…) to work even in HA is unavailable for any reason.

Ok, based on your latest reply, you have another 2 options to look into:

  1. Look up zigbee binding. You should be able to set up your module so that it will directly toggle your bulb using zigbee directly. No need for automations or for HA to be available. You will be need to rewire your bulb as described earlier once this is set up.

  2. At least in Z2MQTT, all Hue bulbs have a setting for power_on_behaviour. This will make your bulb behave the way you want it to after power is restored. If you’re using ZHA, it will depend on whether support for this has been added.

I’ll look into it, thanks!

1 Like