Automation with Xiaomi Motion Sensor and Sonoff with Tasmota

Hi guys,

After a lot of try and error I managed to add xiaomi gateway and flashed sonoff switch into HA.

Now I’m trying to make simple automation with xiaomi motion sensor and lights connected to sonoff switch. I’ve tried with node-red tutorials and HA automation to make it work but no luck.

I have decided to do it in node red and those are two options that i tried.

[{"id":"94cabccd.e116f","type":"tab","label":"Flow 1","disabled":false,"info":""},{"id":"b850c9fe.974278","type":"server-state-changed","z":"94cabccd.e116f","name":"sensor","server":"18ba1fad.acec7","version":1,"exposeToHomeAssistant":false,"haConfig":[{"property":"name","value":""},{"property":"icon","value":""}],"entityidfilter":"binary_sensor.motion_sensor_158d000309fabe","entityidfiltertype":"exact","outputinitially":false,"state_type":"str","haltifstate":"on","halt_if_type":"str","halt_if_compare":"is","outputs":2,"output_only_on_state_change":true,"x":70,"y":80,"wires":[["ce470a2e.02f678"],["6d293437.10707c"]]},{"id":"ce470a2e.02f678","type":"api-call-service","z":"94cabccd.e116f","name":"Bathroom Light On","server":"18ba1fad.acec7","version":1,"debugenabled":false,"service_domain":"light","service":"turn_on","entityId":"switch.tasmota","data":"","dataType":"json","mergecontext":"","output_location":"","output_location_type":"none","mustacheAltTags":false,"x":730,"y":60,"wires":[[]]},{"id":"6d293437.10707c","type":"ha-wait-until","z":"94cabccd.e116f","name":"","server":"18ba1fad.acec7","outputs":2,"entityId":"binary_sensor.motion_sensor_158d000309fabe","entityIdFilterType":"exact","property":"state","comparator":"is","value":"on","valueType":"str","timeout":"2","timeoutType":"num","timeoutUnits":"minutes","entityLocation":"","entityLocationType":"none","checkCurrentState":true,"blockInputOverrides":true,"x":560,"y":180,"wires":[[],["cf1b36d9.1b9798"]]},{"id":"cf1b36d9.1b9798","type":"api-call-service","z":"94cabccd.e116f","name":"Bathroom Light Off","server":"18ba1fad.acec7","version":1,"debugenabled":false,"service_domain":"light","service":"turn_off","entityId":"switch.tasmota","data":"","dataType":"json","mergecontext":"","output_location":"","output_location_type":"none","mustacheAltTags":false,"x":810,"y":160,"wires":[[]]},{"id":"18ba1fad.acec7","type":"server","z":"","name":"Home Assistant","addon":true}]
[{"id":"93451ad6.b51658","type":"tab","label":"Flow 2","disabled":false,"info":""},{"id":"5859daff.cc49e4","type":"server-state-changed","z":"93451ad6.b51658","name":"sensor","server":"18ba1fad.acec7","version":1,"exposeToHomeAssistant":false,"haConfig":[{"property":"name","value":""},{"property":"icon","value":""}],"entityidfilter":"binary_sensor.motion_sensor_158d000309fabe","entityidfiltertype":"exact","outputinitially":false,"state_type":"str","haltifstate":"on","halt_if_type":"str","halt_if_compare":"is","outputs":2,"output_only_on_state_change":true,"x":70,"y":80,"wires":[["e8bfd65d.b32158"],["e8bfd65d.b32158"]]},{"id":"b4ce8eff.ef88","type":"api-call-service","z":"93451ad6.b51658","name":"Bathroom Light On","server":"18ba1fad.acec7","version":1,"debugenabled":false,"service_domain":"light","service":"turn_on","entityId":"switch.tasmota","data":"","dataType":"json","mergecontext":"","output_location":"","output_location_type":"none","mustacheAltTags":false,"x":730,"y":60,"wires":[[]]},{"id":"119b760b.8328da","type":"api-call-service","z":"93451ad6.b51658","name":"Bathroom Light Off","server":"18ba1fad.acec7","version":1,"debugenabled":false,"service_domain":"light","service":"turn_off","entityId":"switch.tasmota","data":"","dataType":"json","mergecontext":"","output_location":"","output_location_type":"none","mustacheAltTags":false,"x":810,"y":160,"wires":[[]]},{"id":"e8bfd65d.b32158","type":"switch","z":"93451ad6.b51658","name":"on or off","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":120,"wires":[["b4ce8eff.ef88"],["fdbcb213.372a1"]]},{"id":"fdbcb213.372a1","type":"trigger","z":"93451ad6.b51658","op1":"1","op2":"0","op1type":"str","op2type":"str","duration":"2","extend":false,"units":"min","reset":"On","bytopic":"all","name":"trigger","x":550,"y":160,"wires":[["119b760b.8328da"]]},{"id":"18ba1fad.acec7","type":"server","z":"","name":"Home Assistant","addon":true}]

Amount of tutorials and different methods is overwhelming, still coundn’t find the solution.
I would appreciate if someone can help me with that :slight_smile: .

Thanks in advance.

edit: Sonoff switch is connected to HA with MQTT