BiDirectional Sensor-Switch sync

Hi there,
I have a stateless remote that toggles on-off an amplifier statelessly (the typical on/off button on a remote).
I connected this to a smart power plug and now I have created a tri-state sensor that tells me if the amplifier is in either of these states:

  • OFF (smart switch gives no power to the amplifier)
  • STANDBY (smart switch measures less than 10W consumption)
  • ON (smart switch measures more than 10W consumption)

Of course I can action my remote with homeassistant via a send_command power_toggle action.

Now I want to to create a stateful STANDBY-ON toggle in such way that:

  • the toggle reflects the sensor (so that if I change the state manually outside of homeassistant, within a short while, the toggle is updated
  • the toggle actions the amplifier (so that if I change the state in homeassistant, the amplifier changes state and the sensor reflects that in a short while)

I am perfectly ok with the toggle to be a 2 state STANDBY-ON toggle, since the “OFF” state is a rare exception that I can let go if it complicates things.

So far I created 2 automations: a “toggle-to-action” and a “sensor-resync” automation with a lock-hold mechanism so that triggering one inihibits the other, but this is far from perfect so far, especially on the resync bit.
some of the challenges I face are:

  • state resync across reboot
  • temporization in case someone triggers both manually and via home assistant at the same time (classic case when 2 people want to turn on music at almost the same time)
  • sometimes resync just won’t trigger (and if it doesn’t trigger right away then the timing is lost and will stay off-sync potentially forever)

any ideas?
I hve seen a blueprint here that seemed a promising first step, but doesn’t have to be.

Forget the automations and just use this:

The turn_on /turn_off actions are your remote commad(s), they can the the same command if it is a toggle command.

The value template will be something like this:

value_template: "{{ is_state('sensor.amplifier_state', 'ON') }}"

OFF and STANDBY states will show the switch as off.

1 Like

That was super simple!! Thank you, this seems to work flawlessly!!

1 Like