Remove .state from the end of your is_state line for checking for 255
is_state needs the entity, not the entities state:
{% elif is_state(“sensor.vision_zg8101_garage_door_detector_alarm_level_10.state”, “255”) -%}
Should be:
{% elif is_state(“sensor.vision_zg8101_garage_door_detector_alarm_level_10”, “255”) -%}
The turn_on and turn_off, being part of the template switch layout, can not be included in the value_template, they have to be stand alone.
Your value template should be an OR
{%- if is_state(‘binary_sensor.vision_zg8101_garage_door_detector_sensor_10’, ‘on’) or is_state(‘sensor.vision_zg8101_garage_door_detector_alarm_level_10’, ‘255’) -%}
This may not work properly since the template sensor should ALWAYS be on or off, but checking against 2 separate sensors that may not always coincide, you may end up with mixed results, where by it may show off if the sensor shows off or the alarm_level shows 0, and it may show on if either the sensor is on or the alarm_level is 255, which may not be the actual state of the door.
The template switches should always be tied to only 1 sensor, so the problem we should be trying to figure out is “what is wrong with the garage door sensor”, because that is your issue, all the rest of this is trying to find a work around to the problem, which is not what the answer is.
I am assuming this binary door sensor is a Zwave device, only because of the _10 at the end usually denotes a Zwave node. If that is the case, I think your problem is that your Zwave network mesh may be inadequate. I don’t know how many powered Zwave devices you have, but garage door sensors tend to be a problem for a lot of people since most people’s garage are on one side of the house or even separate from the house, therefore they are out of range of the Zwave mesh, and only turn on/off intermittently. Powered Zwave devices, that is plugged in the wall, serve as a relay device for the mesh network, but battery operated devices do not serve this same purpose, therefore, if you have no wall powered devices between your garage door sensor and the Zwave hub device, then it may be too far away to update accurately and instead is intermittently updating its state.
Your sensor should be always on or off and always coinciding with the actual state of the door. If it is not, then that has to be addressed, because a door sensor that can not accurately do the one thing it was designed for, which is to sense a binary on or off state, is no longer a door sensor and therefore should not be a part of your home automation system.
It is either broken or not communicating with the Zwave hub device, in which case it should not be relied upon as a state sensor.