home-assistant / core

:house_with_garden: Open source home automation that puts local control and privacy first.
https://www.home-assistant.io
Apache License 2.0
73.23k stars 30.58k forks source link

State of event-based template binary sensor shouldn't be unknown after HA restart #67397

Closed parautenbach closed 2 years ago

parautenbach commented 2 years ago

The problem

I believe this is an edge case not catered for with the introduction (standardisation) of allowing unknown states for binary sensors.

I want to be clear that this isn't an objection against the use of the unknown state – only that there is an edge case where it doesn't actually make sense (to me).

When using template binary sensor triggered by an event, the sensor will have an unknown state (e.g. after an HA restart) until triggered for the first time. At this point, it may still make sense to allow an unknown state, but once the auto_off option gets specified, it indirectly implies a sensor that's normally off (by default) and sometimes on (when triggered). Considering this, it would be impossible for the sensor to have any other state.

It would not be an option to perform any kind of artificial triggering, since it may lead to undesired consequences.

Perhaps one option is to introduce an initial_state option to make this explicit (rather than inferring a default state from auto_off).

There doesn't seem to be any workarounds.

What version of Home Assistant Core has the issue?

core-2022.2.9

What was the last working version of Home Assistant Core?

No response

What type of installation are you running?

Home Assistant Core

Integration causing the issue

template

Link to integration documentation on our website

https://www.home-assistant.io/integrations/template/

Diagnostics information

No response

Example YAML snippet

- trigger:
  - platform: event
    # the type below can really be set to any valid event type for the purposes of illustration
    event_type: amcrest
    # the next section can be omitted, but i wanted to include my full config to make the specific issue clear
    event_data:
      event: CallNoAnswered
      payload:
        action: Start
  binary_sensor:
    name: Doorbell Rang
    state: true
    auto_off: 5  # seconds


### Anything in the logs that might be useful for us?

_No response_

### Additional information

_No response_
probot-home-assistant[bot] commented 2 years ago

template documentation template source (message by IssueLinks)

probot-home-assistant[bot] commented 2 years ago

Hey there @phracturedblue, @tetienne, @home-assistant/core, mind taking a look at this issue as it has been labeled with an integration (template) you are listed as a code owner for? Thanks! (message by CodeOwnersMention)

parautenbach commented 2 years ago

Bump

balloob commented 2 years ago

Don't bump stuff.

emontnemery commented 2 years ago

(Reopened so it's clear the linked PR fixes this issue)

parautenbach commented 2 years ago

Don't bump stuff.

Understood. This was the reason I did: https://community.home-assistant.io/t/issues-closed-without-any-action-from-devs/396238/51.

parautenbach commented 2 years ago

(Reopened so it's clear the linked PR fixes this issue)

Thank you. Really happy to see this fix/improvement.

Should I close the issue now – or what is the process?