Hello, I have a few PIR sensors scattered around my house. I’m using the device_class: motion
with them and they work great. I don’t update my ESPHome devices regularly but when I do update them (or they get rebooted) the PIR sensors come up as Unknown
instead of Clear
. While this is probably wanted in most cases, I don’t want it to be the case on my setup. What’s the best way to set the default state to Clear
on a motion sensor after powerup on ESPHome?
Heh, I thought I was going to answer my own question… I tried this:
publish_initial_state: true
but it didn’t work. After setting that and reloading the FW it still comes up as Unknown
.
Are you using API or MQTT for your HA connection?
I’m using the native API
What version ESPHome? I have a REALLY basic sensor platform using a PIR and a DHT22. The PIR always comes up initially as Cleared.
captive_portal:
# Enable logging
logger:
# Enable Home Assistant API
api:
ota:
sensor:
- platform: dht
pin: D1
temperature:
name: "Office Temperature"
humidity:
name: "Office Humidity"
update_interval: 30s
model: DHT22
binary_sensor:
- platform: gpio
pin: D6
name: "Office PIR"
device_class: motion
Just updated to 2022.10.0 is that what you’re running?
I wonder if it’s my choice of using a delayed off filter…
binary_sensor:
- platform: gpio
pin: D2
device_class: motion
name: "Motion detected in Garage"
filters:
- delayed_off: 5min
That’s the only thing different between me and you if you’re running the latest ESPHome version.
EDIT
That was it. When I commented out the filters:
section it came up as Clear
. Even if I waited the 5 minutes it still never came up – until I triggered the sensor, then it would be on for five minutes and then cleared. I wonder if this is a bug… seems like it to me.
You could always log an issue on ESPHome Github issues register - they will tell you quick enough if it’s behaving as designed…
I put it in their system: GPIO binary sensor initial state is Unknown when using filters and delayed_off · Issue #3722 · esphome/issues · GitHub
Thanks for the help!