Thank you Scott for this lovely piece of work. It’s a clever design and I’ve started to adopt it here.
I already have an item for “Lighting Theme” (E.g. OFF, NORMAL, MOVIE, PARTY, PANIC) that I will synchronize to the “Mode” item. It would be great to be able to use a customized name instead of “Mode” btw. I also have separate modes for Clock_Time_Of_Day
and Solar_Time_Of_Day
that I use in my scripting.
I have defined my own light action function named generic_light_action
and I have set it in the configuration file to be the default, "default_action_function": "generic_light_action"
.
I had some trouble to make it run instead of the light_action
function and I’ve seen it’s been hard coded in the area_trigger.py as
if not action_function_names or "light_action" in action_function_names:
start_action(item, True if event is not None else trigger_group.state in [ON, OPEN], "light_action")
The following modified code works better for me:
if not action_function_names or area_triggers_and_actions_dict["default_action_function"] in action_function_names:
start_action(item, True if event is not None else trigger_group.state in [ON, OPEN], area_triggers_and_actions_dict["default_action_function"])
Cheers!
EDIT: Since the low_lux_trigger
is baked into a named Mode
, I’d also like to add an “ELSE” mode in so that I do’nt have to repeat low_lux_trigger
for every possible mode. I’d like to suggest something like this:
low_lux_trigger = get_key_value(item.name, "area_triggers_and_actions", "modes", str(items["Mode"]), "low_lux_trigger") or get_key_value(item.name, "area_triggers_and_actions", "modes", 'ELSE', "low_lux_trigger") or area_triggers_and_actions_dict["default_levels"]["low_lux_trigger"]`
Then I could just add metadata like the following for a light bulb that’s ON in all modes:
set_metadata("Light_Facade_Tenants", "area_triggers_and_actions",
{
"modes": {
"ELSE": {"low_lux_trigger": 380, "brightness": 60}
}
}, overwrite=True)
And in my area_actions.py
low_lux_trigger = get_key_value(item.name, "area_triggers_and_actions", "modes", str(items["Mode"]), "low_lux_trigger") or get_key_value(item.name, "area_triggers_and_actions", "modes", 'ELSE', "low_lux_trigger") or area_triggers_and_actions_dict["default_levels"]["low_lux_trigger"]
hue = DecimalType(int(get_key_value(item.name, "area_triggers_and_actions", "modes", str(items["Mode"]), "hue") or get_key_value(item.name, "area_triggers_and_actions", "modes", 'ELSE', "hue") or area_triggers_and_actions_dict["default_levels"]["hue"]))
saturation = PercentType(int(get_key_value(item.name, "area_triggers_and_actions", "modes", str(items["Mode"]), "saturation") or get_key_value(item.name, "area_triggers_and_actions", "modes", 'ELSE', "saturation") or area_triggers_and_actions_dict["default_levels"]["saturation"]))
brightness = PercentType(int(get_key_value(item.name, "area_triggers_and_actions", "modes", str(items["Mode"]), "brightness") or get_key_value(item.name, "area_triggers_and_actions", "modes", 'ELSE', "brightness") or area_triggers_and_actions_dict["default_levels"]["brightness"]))
Edit: There is an issue with my code above so don’t use it. The issue is that if a zero brightness is set for an item, it’s sucessfully fetched but the or operator will interprete that as False and go on with fetching the next value in the chain. I have reworked the code since then.
(Needed the int cast due to that get_key_value
might return a float)