Binary_sensor publish_initial_state: false not working

Hi,

I am having a esphome node with a pir and the following definition:

binary_sensor:
  - platform: gpio
    pin: D7
    name: "klo_vorne_PIR"
    device_class: motion
    state_topic: klo_vorne/motion
    publish_initial_state: false

As far as I understood, the state of the PIR should not be published when the device reboots.
But it does.
I am asking because I am using the motion_activated_light blueprint and this does not check if the state is on or off, it just turns the light on if the PIR sensor changes state - and it is a little bit annoying that the lights are turned on every time I change some code or install an update…
Best regards and thanks in advance,
Otto

Weird, I don’t have that problem at all.

publish_initial_state: false

Is the default anyway.

Anyway, I would just drop that blueprint (which isn’t that thought through) and create my own automation, which checks if the light is off, before turning it on.

trigger:
  - platform: state
    entity_id:
      - binary_sensor.bedroom_sensor_motion_sensor
    to: "on"
condition:
  - condition: state
    entity_id: light.bedroom_light
    state: "off"
action:
  - service: light.turn_on
    target:
      entity_id: light.bedroom_light
    data: {}

This way you also have more control over things and can set several parameters when turning on the light. If you have a light sensor you can use its level as another condition, so the light only turns on when it’s dark.

If you still have the problem and find it highly annoying, you could add a switch which would have to be on for the motion sensor to publish its state.

If you do want to progress debugging your current set-up, I think it’s worth posting your full config and some logs.

You may need to connect via usb to get boot logs.

@zenzay42 Thanks! This is a good point :slight_smile:

This is my yaml:

esphome:
  name: "klo_vorne"
  on_boot:
    priority: -100
    then:
      - mqtt.publish:
         topic: klo_vorne/booted
         payload: "1"

esp8266:
  board: d1_mini

external_components:
  - source: github://TheStaticTurtle/esphome_syslog
    components: [syslog]

time:
  - platform: sntp
    id: sntp_time
    timezone: Europe/Vienna
    servers:
      - 192.168.1.1

# Enable logging
logger:
  level: VERY_VERBOSE

syslog:
    ip_address: "192.168.1.6"
    port: 514

# Enable Home Assistant API
api:
  encryption:
    key: "mysecretkey"
  reboot_timeout: 120s

ota:
  password: "mysecretpass"

#deep_sleep:
#  id: dsleep
#  sleep_duration: 0s

wifi:
#  output_power: 8.5db
#  output_power: 15db
  networks:
    - ssid: "sportap"
      password: "pulanpista123"
    - ssid: "serverob"
      password: !secret serverob_password
    - ssid: "speisap"
      password: !secret speis_ap_password
  domain: ".fritz.box"
#    - ssid: "brando_server"
#      password: !secret brando_server_password
  # Enable fallback hotspot (captive portal) in case wifi connection fails
  ap:
    ssid: "klo_vorne"
    password: !secret ap_mode_password

captive_portal:

mqtt:
  broker: mqtt.fritz.box
  username: !secret mqtt_username
  password: !secret mqtt_password
  topic_prefix: klo_vorne
  client_id: klo_vorne
  discovery: false
i2c:
  sda: D2
  scl: D1

interval:
  - interval: 60s
    then:
      - mqtt.publish:
          topic: klo_vorne/heartbeat
          payload: "0"
      - delay: 1s
      - mqtt.publish:
          topic: klo_vorne/heartbeat
          payload: "1"
#klovorne: D2 und D5
sensor:
  - platform: wifi_signal
    name: "klo_vorne_signal"
    update_interval: 120s
    state_topic: klo_vorne/signal
  - platform: uptime
    name: "klo_vorne_uptime"
    update_interval: 300s
    state_topic: klo_vorne/uptime
  - platform: dht
    pin: D5
    model: DHT22
    temperature:
      name: "klovorne_temp"
      state_topic: klo_vorne/temp
    humidity:
      name: "klovorne_hum"
      state_topic: klo_vorne/humidity
    update_interval: 60s
  - platform: bh1750
    name: "klo_vorne_light"
    address: 0x23
    accuracy_decimals: 3
    update_interval: 60s
    state_topic: gang_sz/light
    filters:
      - delta: .01
      - multiply: 100
binary_sensor:
  - platform: gpio
    pin: D7
    name: "klo_vorne_PIR"
    device_class: motion
    state_topic: klo_vorne/motion
    publish_initial_state: false
text_sensor:
  - platform: wifi_info
    ip_address:
      name: klo_vorne_ip
      state_topic: klo_vorne/ip
    ssid:
      name: klo_vorne_ssid
      state_topic: klo_vorne/ssid
  - platform: mqtt_subscribe
    name: "Reboot Trigger"
    id: klo_vorne_reboot_trigger
    topic: "klo_vorne/reboot"
    on_value:
      then:
        - lambda: |-
            if (x == "1") {
              id(restartit).press();
              ESP_LOGD("bla","Rebooting...");
            }
button:
  - platform: restart
    name: "klo_vorne_restartit"
    id: restartit

# Enables status LED
status_led:
  pin: GPIO2

However, after a view re-flashes and reboots, the problem is gone. Weird.
Thanks anyway!

1 Like