I’m developing a custom integration that is configured using ConfigFlow/OptionsFlow.
One of the options is a condition, that I check if it is met before doing my stuff. The problem is that If I create a condition in the UI, it saves OK, I can run and check the condition, all good. The problem is that if I go to the entry in the integration and try to configure it again, the visual editor for the conditions can’t, I can edit it using YAML, but it should be able to edit that it generated.
I don’t know if this is an issue in my code or a bug in the UI.
If some more experiences dev has this issue before or any advice is appreciated.
Hmm that’s tricky. Seems like a core issue, since the frontend does send the config flow with entity_id as a string, but I guess at some point during validation core converts it to an array of string, since it is stored in the config_entry registry that way.
When core sends the condition back to frontend, it sends the array of entity_ids, which is not supported by the visual editor.
Luckily this is not an error, it just means the visual editor can’t be shown for that condition, which is annoying, but you can still proceed.
I don’t think you did anything wrong, it just looks like maybe a bug in core. I expect condition selectors are pretty rarely used, so a lot of these corner cases haven’t been flushed out.
Yeah, it seems it’s not used very often. I searched GitHub and didn’t find any real use cases (only one, to be honest).
In my integration, I’d like to add a condition so that the entry only runs when the condition is met. Is there a more Home Assistant–idiomatic way to do this?
Briefly:
I configure N lights and a timeout.
When any light in this group turns on, I start a timer.
When the timer expires, I turn the light off.
I want the timeout to apply only if a condition is true—like only during the day, or only if another light is on, etc.
I could create an entity for this entry and use an automation to enable/disable it, but I’d prefer something more straightforward.
Another issue:
If I add, say, an offset for sunrise, I can’t save it:
TypeError: Type is not JSON serializable: datetime.timedelta
Also, the horizon offset doesn’t seem to be working correctly…