Given binary sensors a, b, c how can you create a template to return those sensors XOR’ed against each other?
I’m banging my head against the wall on this one.
Given binary sensors a, b, c how can you create a template to return those sensors XOR’ed against each other?
I’m banging my head against the wall on this one.
i don’t know of a true xor operator. so someone else may school me (please do!)
but xor for single bits is just mod 2. so this works for all sensors you have. you can mod this for a group, enumerate them, an area or whatever:
{{ ((states.binary_sensor | selectattr('state', 'eq', 'on') | list | count) % 2) == 1 }}
Along the same line as the answer above:
{{ (('binary_sensor.example_1', 'binary_sensor.example_2', 'binary_sensor.example_3')
| select('is_state', 'on') | list | count %2) | bool }}