Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix binary_sensor initial publish #5038

Closed
wants to merge 3 commits into from

Conversation

dudanov
Copy link
Contributor

@dudanov dudanov commented Jul 2, 2023

What does this implement/fix?

Fixes an error in the initial publication of the state of the binary sensor during the use of filters.

Related issue or feature (if applicable): fixes esphome/issues#2537

https://community.home-assistant.io/t/esphome-fails-to-update-sensor-state-in-ha-when-using-4-second-delay-filters-workaround/347541

Types of changes

  • Bugfix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Other

Test Environment

  • ESP32
  • ESP32 IDF
  • ESP8266
  • RP2040

Checklist:

  • The code change is tested and works locally.
  • Tests have been added to verify that the new code works (under tests/ folder).

If user exposed functionality or configuration variables are added/changed:

@probot-esphome
Copy link

probot-esphome bot commented Jul 2, 2023

Hey there @esphome/core, mind taking a look at this pull request as it has been labeled with an integration (binary_sensor) you are listed as a code owner for? Thanks!
(message by CodeOwnersMention)

Co-authored-by: Jesse Hills <3060199+jesserockz@users.noreply.github.com>
@dudanov dudanov requested a review from jesserockz July 4, 2023 04:34
@dudanov dudanov requested a review from jesserockz July 12, 2023 08:06
@jesserockz
Copy link
Member

Im gonna close this as I think the filters should not alter the data unexpectedly like this. #5091 should fix the problem you were having by publishing false as initial. Let me know if something else is still required though.

@jesserockz jesserockz closed this Jul 12, 2023
@dudanov
Copy link
Contributor Author

dudanov commented Jul 13, 2023

Im gonna close this as I think the filters should not alter the data unexpectedly like this. #5091 should fix the problem you were having by publishing false as initial. Let me know if something else is still required though.

Jesse, I wouldn't create a PR or make corrections if it wasn't required. #5091 does not fix the whole problem. Since the method publish_initial_state still runs through all the filters that delay the publication of the signal. If you are familiar with automation, then there are no and should not be indeterminate states, exceptions in electrical engineering are the so-called Z-states. The standard automation library has functional blocks TON, TOF, etc., they all have certain states at the output. This PR is necessary as it solves this problem.

@jesserockz
Copy link
Member

The main issue I see here is that if you specifically have a filter that delays any state being reported until you need a true or false from startup, this code will break that by forcing a false return.

A BinarySensor has .has_state() to tell you if this sensor has a state published yet or not.

I'll reopen, but not satisfied with the solution (yet)

@jesserockz jesserockz reopened this Jul 13, 2023
@dudanov
Copy link
Contributor Author

dudanov commented Jul 13, 2023

A BinarySensor has .has_state() to tell you if this sensor has a state published yet or not.

In lambda, yes, I can. But this is not an option, especially since the user interface cannot be configured out of the box to display false instead of undefined.

@github-actions
Copy link
Contributor

There hasn't been any activity on this pull request recently. This pull request has been automatically marked as stale because of that and will be closed if no further activity occurs within 7 days. Thank you for your contributions.

@github-actions github-actions bot added the stale label Oct 16, 2023
@github-actions github-actions bot closed this Oct 24, 2023
@github-actions github-actions bot locked and limited conversation to collaborators Oct 25, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Use of delayed_on_off filter in Binary Sensor Component breaks HA sensor updates
2 participants