Skip to content

Add delay feature to Threshold sensor #3168

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

Merged

Conversation

OverloadUT
Copy link
Contributor

Description:
See home-assistant/core#8921

Pull request in home-assistant (if applicable): home-assistant/core#8921

The threshold must be met constantly for on_delay or off_delay amount of time in order to switch to the respective state. Among other things, this allows turning an energy meter in to a "device is running" state, because it can ignore the small periods of time where the energy meter drops to zero.
@mention-bot
Copy link

@OverloadUT, thanks for your PR! By analyzing the history of the files in this pull request, we identified @fabaff and @Kernald to be potential reviewers.

Copy link
Contributor

@Landrash Landrash left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some minor formatting changes that I would suggest but looks good in general.

One question. Isn't this sensor polling other sensors for information?

@@ -39,4 +51,25 @@ Configuration variables:
- **threshold** (*Required*): The value which is the threshold.
- **type** (*Required*): `lower` if the value needs to be below the threshold or `upper` if higher.
- **name** (*Optional*): Name of the sensor to use in the frontend. Defaults to `Stats`.
- **on_delay** (*Optional*): The amount of time the threshold must be met before this sensor will switch to on
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing punctuation at the end of sentence.

@@ -39,4 +51,25 @@ Configuration variables:
- **threshold** (*Required*): The value which is the threshold.
- **type** (*Required*): `lower` if the value needs to be below the threshold or `upper` if higher.
- **name** (*Optional*): Name of the sensor to use in the frontend. Defaults to `Stats`.
- **on_delay** (*Optional*): The amount of time the threshold must be met before this sensor will switch to on
- **off_delay** (*Optional*): The amount of time the threshold must be not met before this sensor will switch to off
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing punctuation at the end of sentence.

@@ -9,7 +9,7 @@ sharing: true
footer: true
logo: home-assistant.png
ha_category: Binary Sensor
ha_iot_class: "Local Polling"
ha_iot_class: "Local Push"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Doesn't this sensor "poll" values from other sensors?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I find the whole IoT Class a weird thing to have on the "meta-sensors" in general. But in this case it's listening to the sensor that it is monitoring, which is basically a push. This will react instantly to state changes rather than having to wait for a polling timer.

I feel like a new "Internal" IoT class is most appropriate, but that's a separate discussion. Perhaps the IoT class should be removed from this sensor entirely?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bringing it up in the #dev chat

@@ -31,6 +31,18 @@ binary_sensor:
threshold: 15
type: lower
entity_id: sensor.random

# If present, sensor will only switch to on if the threshold is met for this amount of time
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing punctuation at the end of sentence.

minutes: 10
seconds: 5

# Same as above, but for the sensor switching to off
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing punctuation at the end of sentence.

This example uses `off_delay` to convert an energy meter connected to a washing machine to determine when a load is finished. During the washer's operation, the energy meter will fluctuate wildly, hitting zero frequently even before the load is finished. By utilizing `off_delay`, we can have this sensor only turn off if there has been no washer activity for 5 minutes.

```yaml
# Determine when the washing machine has a load running
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing punctuation at the end of sentence.

@Landrash Landrash added the new-feature This PR adds documentation for a new Home Assistant feature to an existing integration label Aug 11, 2017
Copy link
Contributor

@Landrash Landrash left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good and can be merged when parent PR is merged.

Discussion brought up about ha_iot_class in #dev chat.

@frenck
Copy link
Member

frenck commented Sep 4, 2017

Closing PR, since parent PR has been closed.

@frenck frenck closed this Sep 4, 2017
@pvizeli pvizeli reopened this Sep 4, 2017
@pvizeli pvizeli merged commit 3d250af into home-assistant:next Sep 4, 2017
pvizeli added a commit that referenced this pull request Sep 4, 2017
pvizeli added a commit that referenced this pull request Sep 4, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
new-feature This PR adds documentation for a new Home Assistant feature to an existing integration
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants