Hey man,
-
First of all try to format your code using three ` characters before and after your blocks, so we can better read what you wrote.
-
Second, does your sonoff connect ok to the mqtt server on hassio? is there an MQT connection message in the tasmota console? You could monitor this from HA’s side if you install an mqtt add-on if you are using hassio or by connecting to the borker with an mqtt client where you can monitor if the tasmota’s messages are being broadcasted.
-
Third, I dont see why you have created a rule to change your mqtt messages on the sonoff.
I personally did like this (but i dont have a button switch as i see in your configuration, just the PIR):
On tasmota, you need to enter the switchtopic comand in order to differentiate your PIR (switch/sensor) topic with the sonoff’s relay topic.
So whatever you have set as a topic in the mqtt settings of tasmota, you need to set something different for to be sent when the PIR is triggered.
For the sonoff relay to work you need to go like this:
My relay topic set in the tasmota gui is sonoff_stairs, which means that my switch is configured with the topic cmnd/sonoff_stairs/power like this:
switch:
- platform: mqtt
name: "sonoff_stairs" #one switch for both sonoffs
state_topic: "stat/sonoff_stairs/POWER"
command_topic: "cmnd/sonoff_stairs/power"
availability_topic: "tele/sonoff_stairs/LWT"
qos: 1
payload_on: "ON"
payload_off: "OFF"
payload_available: "Online"
payload_not_available: "Offline"
retain: false
For the PIR to work, you need to do the following things:
-
Set up the sensor. Inside the COnfigure MOdule menu, you need to set up the gpio to as a switch.
I see you have already set it up asswitch 3nwhich is ok i guess, but the commands would be inverted (? that’s the n part i think) -
You need to differentiate the PIR topic from the Relay topic as mentioned above. This is done with the switchtopic command. In my case
switchtopic: motion/stairs/dn. This will make your tasmota publish this message whenever the pir is activatedcmnd/motion/stairs/dn/POWER1(ignore the /dn/ part, i have two pirs on my stairs). -
Following this documentation, go to your console and set up the PIR correctly. Set switchmode1 acordingly, to turn on/off when motion is detected, in my case i set it to
switchmode1: 1
Get your mobile phone on the console screen and go see if the messages are published correctly when you flap your hands (that’s the fun part!!) -
Then you need to set up the binary switch to listen to that topic, like this:
binary_sensor:
- platform: mqtt
name: Motion Stairs
state_topic: "cmnd/motion/stairs/+/POWER1"
device_class: motion
(the /+/ part is a wild card that will listen to both my topics, cmnd/motion/stairs/dn/POWER1 and cmnd/motion/stairs/up/POWER1, you just set it to what you set as switchtopic above)
Again, i noticed you have a button switch hooked up, the info i gave you will work with just the PIR set up. Maybe disable the pushbutton configuration until you figure out the PIR and take it from there)
Hope i helped more than confused you 
