Sonoff basic with Tasmota PIR and relay as two separate devices in HA

I connected a PIR sensor to GPIO14 of my Sonoff.
it all works fine in HA.
Is it possible to separate the PIR and the relay as two separate devices in HA?
This way I can operate my lamp with one Sonoff and I do not have the click sound of the relay all the time if someone moves and the light is already on.

This is my configuration in HA:


  • platform: mqtt_json
    name: “SN1 LED”
    state_topic: “bruh/sensornode1”
    command_topic: “bruh/sensornode1/set”
    brightness: true
    flash: true
    rgb: true
    optimistic: false
    qos: 0

In Tasmota I have configured GPIO14 as (09 Switch1) andI have not changed anything else.

1 Like

Check here for SwitchTopic 2:

Thanks for the quick response!
it helped me a bit further, but I am not there yet.

I have the PIR instead of a button on GPIO14.
Now I have entered the command “SwitchTopic0 pir” in Tasmota.
The PIR now has no longer control over the relay.
That is going in the right direction, because I want to control the relay separately.
I can still control the relay in HA.
That is also good :slight_smile:
when I move, I see the following message in the Tasmota console:

“16:44:05 MQTT: cmnd/pir/POWER1 = TOGGLE”

this also seems to me a good sign.

I think I only have to setup the switch (PIR) properly in my HA config.

this is how my configuration file looks like now:


  • platform: mqtt
    name: “Sonoff 1”
    command_topic: “cmnd/sonoff2/power”
    state_topic: “stat/sonoff2/POWER”
    qos: 1
    payload_on: “ON”
    payload_off: “OFF”
    retain: true
  • platform: mqtt
    name: “pir”
    command_topic: “cmnd/pir/power1”
    state_topic: “stat/pir/POWER1”
    qos: 1
    payload_on: “ON”
    payload_off: “OFF”
    retain: true

I now have two switches on the dashboard.
“sonoff1” and “pir”
with “sonoff1” I can switch the relay on and off and that work is fine.
the “pir” switch does nothing at all. when I operate it, it switches back on the dashboard.
I would like the “pir” switch to change some state if there is movement, so that I can make an automation to switch the relay on or off.

I feel that I am almost there.

thank you in advance!

Almost there. The PIR is not a switch, you can’t send commands to it, it’s a Sensor. Look here:

thank you!
It works now.
In the Tasmota console I typed “SwitchMode1 1”

And made this configuration:


  • platform: mqtt
    name: pir
    state_topic: “cmnd/pir/POWER1”
    payload_on: “ON”
    payload_off: “OFF”


Are you using one board?
how did you get to change 2 topic in consol " PIR and Sonoff2" and power and power 1?

I am trying to use 2 door sensors with 2 different topic so I can see them on HA. so fare I have only one sensor woking on GPIO14, since i only have 1 topic called door. could you please share the consol codes for your project


than this the mqtt output:

07:59:39 MQT: stat/esp1/RESULT = {“POWER1”:“ON”}
07:59:39 MQT: stat/esp1/POWER1 = ON
07:59:40 MQT: stat/esp1/RESULT = {“POWER2”:“ON”}
07:59:40 MQT: stat/esp1/POWER2 = ON
07:59:42 MQT: stat/esp1/RESULT = {“POWER3”:“ON”}
07:59:42 MQT: stat/esp1/POWER3 = ON
07:59:45 MQT: stat/esp1/RESULT = {“POWER1”:“OFF”}
07:59:45 MQT: stat/esp1/POWER1 = OFF
07:59:47 MQT: stat/esp1/RESULT = {“POWER2”:“OFF”}
07:59:47 MQT: stat/esp1/POWER2 = OFF
07:59:51 MQT: stat/esp1/RESULT = {“POWER3”:“OFF”}
07:59:51 MQT: stat/esp1/POWER3 = OFF


  • platform: mqtt
    name: PIR kantoor1
    state_topic: “stat/esp1/POWER1”
    payload_on: “ON”
    payload_off: “OFF”

  • platform: mqtt
    name: PIR kantoor2
    state_topic: “stat/esp1/POWER2”
    payload_on: “ON”
    payload_off: “OFF”

  • platform: mqtt
    name: knopje kantoor
    state_topic: “stat/esp1/POWER3”
    payload_on: “ON”
    payload_off: “OFF”

But now you can also use rules to do this.

or use esphomeyaml

Finally I had some time to look into my issue.
I misunderstood the concept of the switch ( sensor in my case) and the relay. Thanks a lot for your help.

So my problem was setting up only the GPIOs with a switches without adding GPIOs relays, so the console would show me only POWER for all the sensor when they trigger, I was not seeing POWER1, POWER2 POWER 3 …so I was not able to add the topic for each sensor to my HA.

I was wondering why, but when I used your setting its works, so I guessed the difference with your was the relays.

The links you provide me for rule is little complicated, it looks something interesting although. I was if someone has some examples.


Hello Roy I have your same need to separate the PIR from Relay to integrate it on HA, I followed your configuration but there is something that I do not do well … following the image you posted on your configuration known that the GPIO14 is set “I2C SCL” but in the written description of you referring to have put the PIR in GPIO14 would you be so kind to explain me this passage? thanks in advance Giovanni

yes, I have shifted a bit with the GIO connections. because I wanted to connect a pair of I2c sensors. I have discovered that not every gio is suitable for every task. Rob has completely unraveled this and made a nice youtube video.
as long as you have configured as many relays as switches, it should not be a problem.
I used a D1 mini for this project.

Yes Rob is very clear, unfortunately Tasmotta specifically combines the PIR with the Relay so when when the PIR is TRUE the Relay goes to 1 = ON but to integrate it to HA you have to split the two states and create a rule on “Automation” cmq already with your post are very close to the solution, I have a switch and I have a separate PIR I only have to write well on HA because on the console of Tasmota the PIR has always been TOGGLE both ON and OFF. anyway thanks for sharing … Giovanni

hi ,how do you change the topic name , from power to power 1 or 2 ?
I only get power for the 3 switches I’m trying to set up