I’m trying to template a binary sensor to reflect the states of either of two input sensors. So, if either of the two sensors is on, the new sensor will be on. And, if either turns off, the new sensor will be off. The following template seems to work for only 1 of the two. Can anyone offer suggestions to make it work for both?
{{ 'on' if states('input_boolean.c425_motion' or 'input_boolean.c425_person', 'state') == 'on' else 'off' }}
This also does not work:
{{ 'on' if states('input_boolean.c425_motion', 'state') or states('input_boolean.c425_person', 'state') == 'on' else 'off' }}
and neither does this:
{{ 'on' if (states('input_boolean.c425_motion', 'state') or states('input_boolean.c425_person', 'state')) == 'on' else 'off' }}
You don’t need to include the “on” and “off” values for the new sensor… a template binary sensor will be “on” when it’s template resolves to True, yes, on, enable or a positive number. If it resolves to anything else it’s state will be “off”
The basic OR is:
If either is “on”, the new sensor would be “on”.
If both are “off”, the new sensor would be “off”
{{ is_state('input_boolean.c425_motion', 'on')
or is_state('input_boolean.c425_person', 'on') }}
That’s not a basic OR… are you sure that’s the correct logic?
What you have described will need triggers because you need to track the “on to off” and “off to on” events.