Hey guys,
I just got into figuring out how mqtt works so, please bare with me if i am missing something stupid
I need some help on how to set up my mqtt staircase lights.
The tl;dr version is that although PowerOnState is set to 1 in the tasmota firmware, unfortunately, when switching the lights on through the wall switch, they just stay on for 4-5 seconds then go off again.
Here is my set up:
- Two lights, one in each side of my staircase, both wired to wall switches.
- I installed a small sonoff basic flashed with tasmota box inside each one.
- This means the sonoff only boots when the wall switch turns on.
- Each sonoff has a PIR sensor connected and so far everything works well.
- Both pirs are set up as an mqtt binary sensor in my HA which turns on the lights, then off after a delay of 120sec.
I have provided my detailed configuration below, and it all works fine, when both the switches are on and the sonoffs are active, the motion sensors work great and activate them.
My desired functionality would be for the sonoffs to power up and stay on when booting up (when i turn my wall switch off and on again) - or ideally, also turn off after a time delay.
What happens now is that the lights do turn on but turn off around 4-5 sec.
00:00:00 Project sonoff Sonoff Stairs Dn (Topic sonoff_stairs, Fallback sonoff_stairs_dn, GroupTopic sonoffs) Version 5.10.0
00:00:00 WIF: Connecting to AP1 XXXXX in mode 11N as sonoff_stairs-1627...
00:00:02 RSL: stat/sonoff_stairs/RESULT = {"POWER":"OFF"}
00:00:02 RSL: stat/sonoff_stairs/POWER = OFF
00:00:03 WIF: Connected
00:00:03 DNS: Initialized
I am getting this RSL power off as soon as it boots up, Is that the problem?
Alternatively and ideally, if the sonoff could send a motion detection mqtt command when it boots up, that would be great as it would also respect the two minute timer and turn off again. Is there a way to send an mqtt command on boot? I understand that birth message
is something like that,but that is issued broker-side right? is there something similar on client side?
I’m going to provide my full code, probably going to help someone:
configuration.yaml:
mqtt:
(using the built in broker)
switches.yaml:
- platform: mqtt
name: "sonoff stairs"
state_topic: "stat/sonoff_stairs/POWER"
command_topic: "cmnd/sonoff_stairs/power"
payload_on: "ON"
payload_off: "OFF"
binary_sensors.yaml:
- platform: mqtt
name: "sonoff motion stairs"
state_topic: "cmnd/motion/stairs/+/POWER1"
payload_on: "ON"
payload_off: "OFF"
qos: 0
device_class: motion
Both my sonoffs are listening to cmnd/sonoff_stairs/power
Both switchmode1 1
And both sensors broadcast cmnd/motion/stairs/up/POWER1
and cmnd/motion/stairs/dn/POWER1
by switchtopic motion/stairs/up
and switchtopic motion/stairs/dn
in the console as this guy.
I have also set PowerOnState 1
and PowerRetain 0
on both as per the tasmota guide
my automations.yaml:
### STAIRS PIR
- action:
- alias: Turn On stairs lights
service: switch.turn_on
entity_id: switch.sonoff_stairs
alias: Motion stairs ON
id: '1506607652748'
trigger:
- entity_id: binary_sensor.sonoff_motion_stairs
from: 'off'
platform: state
to: 'on'
- action:
- alias: Turn off stairs lights
service: switch.turn_off
entity_id: switch.sonoff_stairs
alias: Motion stairs OFF
condition: []
trigger:
- entity_id: binary_sensor.sonoff_motion_stairs
platform: state
to: 'off'
for:
seconds: 120