I’d would love to have state.context to be part of the automation UI. That way I can easily make automation exceptions for entities that are manually changed via my dashboards.
This already exists.
I don’t see how I can use this in the UI. Neither I can find it anywhere else in the UI. I’m using 2022.5.5. Can you tell me where to find it in the UI?
No. I don’t use the automation editor.
This is very vague. What do you want to do with the context in automations? Be explicit, otherwise you can access this info in the UI via templates.
I want to be able to make automation which do stuff and do other stuff when some entity’s state has changed through user influence (for instance through the Lovelace dashboards)
Example: I have a wall switch that I can use to turn some light on and off with. I can also control this switch via HA, e.g. as light.kitchen.
How can I now differentiate the method by which the light was changed?
- When I use the physical switch
- When I manually invoke an HA service to turn the light on or off
- When an automation calls such an HA service
You’re quoting half a sentence.
Yes, the important half. Where you did not supply the requested information. “Stuff” is not explicit.
But fine I’ll make my description less abstract. I have an automation for my backyard lights. It goes on with 10% brightness when outside lux is measured to be less then 10. Also it goes on 70% brightness when I open one of two doors to the backyard.
It turns off the lights when I close the doors or when it is past 23:30h.
But when I turn on the lights through their dashboard switch in Lovelace I want it to disable the automation. (and yes I know this can be done with a helper, but I think state.context is the way to go)
Stuff is not important. But just for you I supplied it.
HA has no concept of who physically used a switch. It just knows when there’s no context.
What do you mean “manually”? Context only works in scripts or automations. So it depends on how you’re using the automation. But to circle back, you can currently use this in automations in the UI. You just need to use a template because the context changes depending on the trigger, action(service), condition, and position in the automation.
See above.
See this truth table that shows the context options:
So an automation that detects a dashboard input would have to pass these conditions:
condition:
- "{{ trigger.to_state.context.id != none }}"
- "{{ trigger.to_state.context.parent_id == none }}"
- "{{ trigger.to_state.context.user_id != none }}"
So maybe I should rephrase my whole topic? To be more like: UI option what the cause of an entity to change state is?
To be honest now my topic just releases a discussion about how to use context or what context can do for me. But as I understand correctly context is not what I need.
You can only check if it was a dashboard action, and automation or a physical control.
Which is exactly what I want. But I want to be able to use it from the UI. I’m no programmer. Templating gives me the creeps.
Ok, that’s fine. But you still haven’t explained where you want to use it in the UI. Condition? Trigger? Action?
This is why I siad:
because this quote below does not fit into anything that HA can do without templates.
Long story short, HA can already get the context out with templates.
If you want to use it as a condition, that can be built pretty easily. However if you want to use the context in a message… well, you have to use templates as there’s no way to “Get information” in an automation without using templates.
If you want to have something in a trigger, that can probably be built too pretty easily. But circling back, using that info later in the automation will force you to use templates.
TLDR: The only way to get ANY information out to use in an automation is through templates, which can already do this.
I explained my use case. And for now I would settle with the condition of an automation. In the future maybe also in the choose of an action too.
But my feature request is not about how to do it (because it is clear to me that it can be done with templating), it is about to be able to do it in the UI without any templating knowledge. Just like some other features you can do in the UI these days. Which weren’t possible in the past.
I’m just hoping some developer sees this as useful and easy to implement for a future iteration of the automation UI. I can imagine other people have use cases for this since there are a lot of people having automations and dashboards with switches to change entities.
Chooses and conditions would go hand and hand. They use the same code.
And this simply won’t be possible in messages, which would be the other place you’d want to use it outside of triggers and conditions.
The best case you’ll get here is a simple template variable that contains the context in a friendly manner without writing code. Unfortunately, if you want to use custom messages with information extracted from the automation/script, you’ll need to use templating. That’s why templating was added into HA in the first place.