-
-
Notifications
You must be signed in to change notification settings - Fork 32.4k
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
Allow MQTT sensor expire_after to be a float value. #20716
Conversation
I think Hass is working with an integer second precision internal timer, are you sure this works as intended? Please see discussion in #16993 |
I've added logging https://github.com/home-assistant/home-assistant/blob/22820ccae58a570fc5671bae87b3d0217a3eda69/homeassistant/components/mqtt/sensor.py#L139 and https://github.com/home-assistant/home-assistant/blob/22820ccae58a570fc5671bae87b3d0217a3eda69/homeassistant/components/mqtt/sensor.py#L190
This seem to trigger the |
@emontnemery is right, our internal clock is based on 1 second so allowing floats to be entered would be incorrect as we can't deliver. |
@balloob I agree, perhaps what we need is something like a MQTT event trigger sensor. Background information sensor:
- platform: mqtt
value_template: '{{ value_json.click }}'
state_topic: 'zigbee2mqtt/my_button'
name: my_button_click A button can have multiple click types, e.g. To respond to these button clicks, we wan't an automation in the form of: - alias: Resond to button click
trigger:
platform: state
entity_id: sensor.my_button_click
to: 'single'
action:
entity_id: light.my_bulb_light
service: light.toggle This works for the first button click as the state changes from By using the Another limitation of the What would be a good solution to this? |
The good solution here is to follow our policy of not trying to store button clicks in the state machine but fire events instead. This is how every other platform does it. Will close this PR as this won't solve it. |
Or I guess in the case of zigbee2mqtt, just have an automation with an MQTT trigger listen to the correct topic. |
@balloob this is indeed how it is currently done, however it would be a cleaner solution if the home assistant entity IDs could be used in the automations. |
I still think the solution is to send an MQTT event from zigbee2mqtt changing the state back
MQTT guarantees message order, so in this way no need to worry about the cooldown period being affected by low resolution timers in HomeAssistant or by delays caused by the MQTT broker. Btw, if you implement the button as a binary_sensor there's always this: |
Description:
Currently when setting
expire_after
of a MQTT sensor to e.g.0.4
theexpire_after
mechanism is not triggered. This is because theexpire_after
value is rounded to0
resulting in theexpire_after
mechanism to be disabled.This PR fixes that problem by interpreting the
expire_after
as a float value.Related issue (if applicable): not applicable
Pull request in home-assistant.io with documentation (if applicable): not applicable
Checklist:
tox
. Your PR cannot be merged unless tests passIf user exposed functionality or configuration variables are added/changed: not applicable
If the code communicates with devices, web services, or third-party tools: not applicable
If the code does not interact with devices: not applicable