How to Get PIR Sensor to show in Home assistant using Sonoff with Tasmota

Hi Guys.
I have a sonoff basic with Tasmota firmware. I have a PIR connected to GPIO3 (can use 14 if need be) I do not want to use PIR to trigger the sonoff relay. I am only using Sonoff as means of using MQTT to be able to set some automatons using MQTT and or Service calls.
So when the motion sensor triggers, I would like it to send a message to turn a hue light on, in daughter’s bedroom via a automation.
I have the following in Binary Sensor yaml file

  • platform: mqtt
    name: “JessRoom Motion”
    state_topic: “JessRoom/PIR/state”
    availability_topic: “tele/jessroom/LWT”
    qos: 1
    payload_on: “YES”
    payload_off: “NO”
    payload_available: “Online”
    payload_not_available: “Offline”
    device_class: motion

This is from the console of Sonoff when the PIR is triggered

23:28:52 RUL: SWITCH3#STATE=1 performs “publish JessRoom/PIR/state YES”
23:37:22 MQT: JessRoom/PIR/state = YES
23:37:32 RUL: SWITCH3#STATE=0 performs “publish JessRoom/PIR/state NO”
23:37:32 MQT: JessRoom/PIR/state = NO

This is the binary senor in States. It does not change. When PIR is triggered, the STATE always shows “off” It does not change to “On”

binary_sensor.jessroom_motion Off friendly_name: JessRoom Motion device_class: motion

What am I doing wrong and how can I get this work so the State changes when the PIR motion is active? Then I can setup the Automations for it
As per “digiblur” youtube video, there are some rules setup

rule2 on switch3#state=1 do publish JessRoom/PIR/state YES endon on switch3#state=0 do publish JessRoom/PIR/state NO endon

I am still learning and slowly understand all the workflows and functions
Thanks everyone in advance everyone.

Bruce

Just starting at the start, what do you have setup in the module side of Tasmota?

Config > Module

Ok so
Module Type Sonoff Basic (1)
GPIO1 = Switch 3n = PIR
GPIO3 = Switch 1(9) = Push Button
GPIO14 = Switch 2n = Not in use at present
MQTT settings
Host = IP address of HA
Port = 1883
Client = DVES_%06X
User = brucys
Password = my password
Topic = jessroom
MQTT enabled

Thanks for coming back to me @automationpirate

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:

  1. 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 as switch 3n which is ok i guess, but the commands would be inverted (? that’s the n part i think)

  2. 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 activated cmnd/motion/stairs/dn/POWER1 (ignore the /dn/ part, i have two pirs on my stairs).

  3. 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!!)

  4. 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 :slight_smile:

1 Like