#Ref Counting Lights?

1 messages · Page 1 of 1 (latest)

kindred prawn
#

I'm new to HA, but my first use case seems to be so hard I must be doing something wrong. I have outside lights A, B, C, D. And want the following

  1. Around subset A comes on
  2. At midnight A, B, C, D all go off
  3. Switch S1 on, A, B, C should come on
  4. Switch S1 off, A, B, C should go to whatever state their default state should be e.g. A will be on if its before midnight, off after
  5. Switch S2 on, A, C, D should come on
  6. Switch S2 off, A, C, D should come on revert to their default state
  7. Motion detected A, C, D should come on for 10 mins, before reverting to their default state (which depends on time and S2)

In essence I have a back light (S1), front light (S2) and motion sensor and they all overlap on what lights to turn on/off.

I can technically program this with huge numbers of complex interacting automations - but it's impractical to keep straight. I can get close with a save/restore state script, but it gets confused if they overlap. I can see a way with lots of helpers I could probably do it as well, but again, wildly complex. Am I missing some easy option?

What I really want is assertion/ref counting lights where each of the above actions turn_on a set of lights which increments a refcount for the light, and at off, decrements it - but the light only goes off if refcount == 0. That way they can overlap all they want and it would work logically regardless of the ordering/overlap

earnest skiff
#

I would use labels.
Lights can have multiple labels, so everything for each of scenario 1,2,...7 above has a different label, and when you switch the scenario turn them all off then turn on the label.

kindred prawn
#

The problem isn't how I collate them, it's how I determine the correct state at revert

#

Let me give an example. It's night, so A is on. I turn on S1 to put the bins out, A, B, C are on. I walk our the front of my house, motion is detected and A, C, D come on. If I'm still out front the 10mins expires, I want it to revert to A, B, C on. But if I've turned off S1 that revert is just A on

earnest skiff
#

You have a lot of complication no matter what you do there.

#

Draw a flowchart, then you might see a pattern that can shortcut things.

kindred prawn
#

In case anyone else has a similar problem. I appear to have solved it like this:

  • Create a set of labels for the different groups (scenes probably work as well)
  • Create identically named template helper switch's to track the state e.g. in my case I have "Bin Lights", "Arrival Lights", "Garden Evening Lights"
    • these have no state template, their "on" action turns on the labled lights
    • their "off" actions "script.on" (important) a script called "reconcile outside lights"
      script on is important so it runs async and sees the switches changed state
#

the reconcile script looks like this

{% set participating_switches = ["Arrival Lights", "Bin Lights", "Garden
Evening Lights"] %}

{% set ns = namespace(exclusion_list = []) %} {% for name in
participating_switches %}
{% set switch_id = 'switch.' ~ (name | slugify(separator='_')) %}
{% if is_state(switch_id, 'on') %}
{# If the switch is ON, get all entities with the label matching the switch name and add them #}
{% set lights_to_exclude = label_entities(name) | list %}
{% set ns.exclusion_list = ns.exclusion_list + lights_to_exclude %}
{% endif %}
{% endfor %}

{% set all_lights = label_entities('Outside Lights') | list %} {{ all_lights |
reject('in', ns.exclusion_list) | list }}

#

basically it looks at all my outside lights, removes any which the switches say should be on, and then turns the rest off

remote chasm