Mirror virtual switch with physical switch. Tasmota and Smartthings

Hey. My googlefu is failing me, I can’t seem to find any solutions to what I am trying to do.

I have tasomota-sonoff’s wired in my house. I have smartthings because i liked it’s samsung phone integration.

I have hassio setup on a pi. it is running a MQTT server. My smartthings is bridged to it. as well as my tasmota switches are connected to it. I also have tasmota admin.

So what I want to do is set up a virtual switch on my smarthings, then have that linked to the physical state of the light. That way when the physical state is changed, it updates the switch status in my smartthings immediately.

The tricky part is having both switches mirror each other with out going into a loop. So far I have a flow in node red that watches for the topic of the virtual switch and changes it to control the lamp i test with.

But I haven’t figured out the reverse flow with out causing a loop.

ideas?

Sounds like you would get better help for what you are asking on the smartthings forum. It doesn’t sound like a Home Assistant question…

Im using the same logic with several virtual switches in Smartthings. Works like a charm. Please find below one NodeRed Flow Example.

[{"id":"317a2973.8db416","type":"api-call-service","z":"45f89900.2e2b58","name":"","server":"2fba4297.e4145e","version":1,"service_domain":"input_boolean","service":"turn_on","entityId":"input_boolean.abkuhlen","data":"","dataType":"json","mergecontext":"","output_location":"payload","output_location_type":"msg","mustacheAltTags":false,"x":680,"y":400,"wires":[[]]},{"id":"e983c8a0.87fe98","type":"api-call-service","z":"45f89900.2e2b58","name":"","server":"2fba4297.e4145e","version":1,"service_domain":"input_boolean","service":"turn_off","entityId":"input_boolean.abkuhlen","data":"","dataType":"json","mergecontext":"","output_location":"payload","output_location_type":"msg","mustacheAltTags":false,"x":680,"y":460,"wires":[[]]},{"id":"1f5d4790.2a36e8","type":"switch","z":"45f89900.2e2b58","name":"","property":"payload","propertyType":"msg","rules":[{"t":"eq","v":"on","vt":"str"},{"t":"eq","v":"off","vt":"str"}],"checkall":"true","repair":false,"outputs":2,"x":410,"y":400,"wires":[["317a2973.8db416"],["e983c8a0.87fe98"]]},{"id":"ca60c679.b203a8","type":"server-state-changed","z":"45f89900.2e2b58","name":"Abkühlen On?","server":"2fba4297.e4145e","version":"1","entityidfilter":"input_boolean.abkuhlen","entityidfiltertype":"substring","outputinitially":false,"state_type":"str","haltifstate":"","halt_if_type":"str","halt_if_compare":"is","outputs":1,"output_only_on_state_change":false,"x":90,"y":520,"wires":[["466f9d27.5e7d54"]]},{"id":"466f9d27.5e7d54","type":"switch","z":"45f89900.2e2b58","name":"","property":"payload","propertyType":"msg","rules":[{"t":"eq","v":"On","vt":"str"},{"t":"eq","v":"off","vt":"str"}],"checkall":"true","repair":false,"outputs":2,"x":410,"y":520,"wires":[["536e82fa.78200c"],["d75ad5b9.a4cec8"]]},{"id":"c86312c7.e5a92","type":"server-state-changed","z":"45f89900.2e2b58","name":"ST Dyson Wohnzimmer","server":"2fba4297.e4145e","version":1,"entityidfilter":"switch.dyson_wohnzimmer","entityidfiltertype":"exact","outputinitially":false,"state_type":"str","haltifstate":"","halt_if_type":"str","halt_if_compare":"is","outputs":1,"output_only_on_state_change":true,"x":120,"y":400,"wires":[["1f5d4790.2a36e8"]]},{"id":"536e82fa.78200c","type":"api-call-service","z":"45f89900.2e2b58","name":"","server":"2fba4297.e4145e","version":"1","service_domain":"switch","service":"turn_on","entityId":"switch.dyson_wohnzimmer","data":"","dataType":"json","mergecontext":"","output_location":"payload","output_location_type":"msg","mustacheAltTags":false,"x":650,"y":520,"wires":[[]]},{"id":"d75ad5b9.a4cec8","type":"api-call-service","z":"45f89900.2e2b58","name":"","server":"2fba4297.e4145e","version":"1","service_domain":"switch","service":"turn_off","entityId":"switch.dyson_wohnzimmer","data":"","dataType":"json","mergecontext":"","output_location":"payload","output_location_type":"msg","mustacheAltTags":false,"x":650,"y":580,"wires":[[]]},{"id":"2fba4297.e4145e","type":"server","z":"","name":"Home Assistant","legacy":false,"hassio":true,"rejectUnauthorizedCerts":true,"ha_boolean":"y|yes|true|on|home|open","connectionDelay":true}]

I have found for on/off there is no loop. However, for mirroring things like brightness or volume there can be some issues. I employed a message filter and a function check to only allow values that differ from previous values in this case

can you explain it to me a little?

It doesn’t import well. has errors.

If i am understanding.

it watches the state of the device, and of the virtual switch. Then it tells the device on both to change states to the same thing. correct?

Correct:

The Smartthings switch is monitored and will turn on or off the corresponding input boolean - vice versa

I kind of found this to be a little unreliable.

The states of the virtual switches aren’t correctly updating all the time from the dashboard. However, so far using the app to change the switch seems to be working.

I added a function to watch the tasmota state topic and adjust the smartthings virtual switches to match the actual state.

I think there is almost a disconnect between hassio and the smartthings mqtt bridge. I have noticed sending commands to it from hassio don’t always change the state on the app. even though the bridge is showing it has received the message.

Yes using the mqtt bridge i always had problems. But using the native hassio smartthings link it works fine.

ok, so now i find if i flick the physical switch rapidly it will go into a loop. I have kids, so it’s bound to happen. lol. any idea how to put a loop break into it?

Edit: So I found the delay node can limit message rate and block additional messages received during the delay. effectively stopping the loop.

flow

1 Like

if anyone encounters a need for this. I turned the above node red flow into this

nr

But now I have found node red to be too hard on my pi3 b+. so in an effort to save on resources, I migrated into home assistant automations.

- alias: SmartThings virtual switch mirror 1 Basement hall light
  trigger:
    platform: state
    entity_id: light.basement_hall_light
    to: 'on'
  condition:
    condition: state
    entity_id: switch.basement_hall_light
    state: 'off'
  action:
  - delay: 00:00:01
  - service: switch.turn_on
    entity_id: switch.basement_hall_light
#
- alias: SmartThings virtual switch mirror 2 Basement hall light
  trigger:
    platform: state
    entity_id: light.basement_hall_light
    to: 'off'
  condition:
    condition: state
    entity_id: switch.basement_hall_light
    state: 'on'
  action:
  - delay: 00:00:01
  - service: switch.turn_off
    entity_id: switch.basement_hall_light
#
- alias: SmartThings virtual switch mirror 3 Basement hall light
  trigger:
    platform: state
    entity_id: switch.basement_hall_light
    to: 'on'
  condition:
    condition: state
    entity_id: light.basement_hall_light
    state: 'off'
  action:
  - delay: 00:00:01
  - service: light.turn_on
    entity_id: light.basement_hall_light
#
- alias: SmartThings virtual switch mirror 4 Basement hall light
  trigger:
    platform: state
    entity_id: switch.basement_hall_light
    to: 'off'
  condition:
    condition: state
    entity_id: light.basement_hall_light
    state: 'on'
  action:
  - delay: 00:00:01
  - service: light.turn_off
    entity_id: light.basement_hall_light