-
-
Notifications
You must be signed in to change notification settings - Fork 30.2k
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
Fire numeric_state action when first state change matches criteria #10125
Fire numeric_state action when first state change matches criteria #10125
Conversation
That is not a bug, that is a feature. We do setup automation as last platform. We don't know if a sensor is initial with a old state or new state or have they change between last startup. In passt, we was every start wired while we can't know the exactly direction. That is the reason why we change this on 0.39. Maybe not all people love it while he don't understand how the automation work and then he need only set startup as trigger to trigger a automation after startup and the condition need set the correct state of home to run the correct and needed action and not the trigger should represent the state to run the action.
Yes that is a bug. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Look good
|
||
if value_template is not None: | ||
value_template.hass = hass | ||
|
||
@callback | ||
def check_numeric_state(entity, from_s, to_s): | ||
"""Return True if they should trigger.""" | ||
if to_s is None: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Don't remove this or we trigger it if we remove a state from state machine
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I removed this because the test seems to happen anyway in condition.async_numeric_state
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can believe me, it's needed. I add to my task list, that I will add a test for this case. But yeah it is rare.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pascal is correct. Needs to be added back.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I trust you but I am really curious, can you explain why this async_numeric_state
check is not sufficient?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Safe memory and is optimize. We need not create a function frame to stack if we already know that we not need do this. The dict that follow eat in this case only memor and process in wors case a memory leak on heap
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm, I am not sure that I agree with an optimization argument. This is optimizing the unlikely case while making the common case a little bit slower with two identical tests. Extra code also takes up memory :)
Never mind, I will add it back no problem. For sure, there are code style and robustness cases that can be made.
Thanks.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh interesting, I wasn't aware there was another check in the condition. I still think it's good to just be explicit to people reading the trigger code what is going on . Thanks for putting it back 👍
I am happy that we agree the two automations should work identically, that was my main beef with this. Personally, I do not feel strongly about which way is best but I think it is excessive that you have to specify the same conditions twice if you also want it to fire during startup. This is speaking from a usability point of view, I do understand that it is a nice clean architecture :) |
Ready to merge after my commend is addressed |
All right, I woke up with the insight that this consistency issue of course also applies to other triggers such as So I am a bit confused that you say this PR can be merged. I have to change the firing back to work like before, right (i.e. not modify any tests)? I do think the changes in this PR are also a cleanup so I will be happy to fix it up and have it merged. |
Now I'm not sure what the main idea or behave is. The code is okay if we have right. EDIT: Sun trigger looks also okay. So It's only a problem of numeric_state. EDIT: Remove text that could be missanderstand in context of that PR |
I think that the first state change to come in for a numeric trigger should trigger the automation. We should not wait for a state to be first below the threshold. |
Wow, so I was right from the start and now I convinced myself to be wrong? Well I will just address the comment then :) |
That was not for the change request. I mean the handling while we had a test to explicit protect this |
Thought I'd weigh in as the severely confused user. I strongly agree with @balloob and @amelchio's original position: the initial state should trigger the automation. If I setup something like: - alias: 'Monitor CPU temperature'
trigger:
platform: numeric_state
entity_id: sensor.cpu_temperature
above: 200
action:
- service: notify.slack
data:
message: Your Raspberry Pi is melting. My assumption is I will be notified whenever the CPU temperature is above 200° — period. I'd hate to discover my Pi had turned into a puddle of plastic and silicon just because it was already running hot when HASS was started. |
Yeah, that is correct and that is not the point @aaronwolen |
sorry @amelchio that is childish, If done while I had other 80 PRs to review and no time for that shit |
@pvizeli I have no idea what childish shit you talk about. I apologize for any perceived rudeness and can assure you that it is only due to failed communication. @aaronwolen Likewise, I hope you didn’t take my description the wrong way. It was meant to convey that the implementation is currently confusing, not that anybody is a confused person in general :) |
@amelchio, not at all! It was indeed my confusion regarding |
Travis is not realated to this changes |
@amelchio I'm sorry. The comment was to hard and over the target. It also not conform to our https://home-assistant.io/code_of_conduct/. In this case I apologize me. |
@pvizeli Thank you, that is much appreciated. |
Description:
This changes the
numeric_state
trigger to potentially fire on its first state change, even if the criteria were already met when the automation was created. That makes these two automations work in the same way:The current situation is that
template
will fire even without crossing the threshold butnumeric_state
will not. This inconsistency has caused severe confusion, like seen in this forum post (with links to several more).I know this change is (once again) a bit controversial; you can easily argue that it should only fire when the threshold is actually passed. However, I think it is handy when developing automations to have it fire on startup and I definitely think the above two triggers should work in the same way.
There is a deeper problem that I do not know how to fix: when setting up sensors, the automations are not yet running. So, confusingly, things will not fire on startup but rather on the first change.
Pull request in home-assistant.github.io with documentation (if applicable): home-assistant/home-assistant.github.io#<home-assistant.github.io PR number goes here>
Checklist:
If user exposed functionality or configuration variables are added/changed:
If the code does not interact with devices:
tox
run successfully.