The automation State Trigger triggers when the binary_sensor’s state changes from on to off.
The condition will pass if the binary_sensor’s object_id exists as one of the keys in the detectors dictionary (it should pass).
Because the binary_sensor is off, the value of trigger.to_state.state will be off. Therefore it will serve to fulfill the second choice in the choose which turns off the associated light and input_boolean.
detectors is simply the name I chose for the variable containing the dictionary. It’s an abbreviation of Motion Detectors.
Yes, I am trying to understand how it actually works, as I think your method is really neat, so I could see myself use that other places also.
This part: value_template: “{{ trigger.to_state.object_id in detectors.keys() }}” what does that actually do? It goes to the trigger part and then afterward to the detector part and the corrosponding key?
So for the first example it goes to this trigger: “- binary_sensor.gang_sensor_home_security_motion_detection” and then the corrosponding key in detector part is “gang_sensor_home_security_motion_detection”?
Is this a bit the same under action: " detector: “{{ detectors.get(trigger.to_state.object_id, none) }}” does that go to the correct variable and then get the ID of each of the variables ready for use further on?
Last question, what does the “100” do in this one? brightness_pct: “{{ detector.modes.get(states(‘sensor.day_interval’), 100) }}”
Sorry for the many questions, and once again thanks for the support
The following Template Condition checks if the object_id of the entity that triggered the State Trigger exists as one of the keys in the detectors dictionary.
{{ trigger.to_state.object_id in detectors.keys() }}
It serves as a safeguard to prevent errors in case you add another binary_sensor to the State Trigger but forget to add a corresponding key (and other information) for that new entity in the dictionary.
The detector variable is set to the dictionary key, in the detectors dictionary, that corresponds to the binary_sensor that triggered the State Trigger. It does that using the following template:
If there’s no matching key, the value of detector is set to the default value none (which is a null object). It’s unlikely it will ever be set to none because the automation’s condition has already confirmed there’s a matching key. However, it’s good practice to specify a default value.
The 100 in the following template represents the default value that will be reported if there’s no matching key found in the modes dictionary. In this case, if the value of sensor.day_interval can’t be found, the light’s brightness is set to 100. Feel free to change the default value to whatever brightness level you think is best for your needs.
Please consider marking my post above (the one containing the automation example) with the Solution tag. As the author of this topic, you get to choose one post that best answers/solves your original question/problem. By marking the post, it will automatically place a check-mark next to the topic’s title which signals to other users that this topic has been resolved. It helps users find answers to similar questions.
I have tried to extend the automation a bit, since one of the rooms should only react if an input boolean is on, but for the others it should always work. I then tried to add this boolean to the variables as a “dummy”, but that doesn’t seem to work, any inputs?
It works just fine for the one using the actual input boolean, but the ones with
rooms_aut: "on"
does not work.
Is it possible to make it work, or alternatively in the condition define it to check the condition if valid in the dictionary and if not set it to “on” as default?
Did you use the Automation Editor to create/modify the automation? It has a habit of changing boolean values to strings. In other words, it can change rooms: true to rooms: 'true' which will then fail to work properly in the Template Condition. Check the automation and confirm the boolean value is still boolean and not string.
The automation continues to work great, but since then I have made a helper called “input_number.luxgraense” which is just a slider that provides a number (for instance 180) to be used as a threshold for when the light should trigger or not.
The above doesn’t work this is what is in the log: “Error in ‘choose[1]’ evaluation: In ‘template’ condition: UndefinedError: ‘input_number’ is undefined”. Any ideas?