Need one state combined from two sensors

Hi. For the gate opener I need a status indication OPEN/CLOSE.
it might be on the line of gate related switch or in the form of “single sensor” indication.
This status is based on 2 sensors where one is ON second OFF for OPEN and vice versa.
Switch “toggle” gate only, i.e. one click/impuls - gate opens, next click - gate closes.
At the same time gate might be opened by its own remote.
I would like to have an indication if it is open or closed.
I am able to read and indicate each sensor separately but not able to use them together.

Appreciate any guidance :slightly_smiling_face:

You need a template sensor

Great, thanks. Going to test it later on today.

I made entry to sensors.yaml:

  -  platform: template
     sensors:
       Alarm:
         friendly_name: "sonoff"
         value_template: "{{ value_json.['Switch1'] }}"

       Alarm2:
         friendly_name: "sonoff2"
         value_template: "{{ value_json.['Switch1'] }}"    

Got this error message:

Failed config
  sensor.template: 
    platform: template
    sensors: [source /config/sensors.yaml:38]
      Alarm: [source /config/sensors.yaml:39]
        friendly_name: sonoff
        value_template: {{ value_json.['Switch1'] }}
      Alarm2: [source /config/sensors.yaml:43]
        friendly_name: sonoff2
        value_template: {{ value_json.['Switch1'] }}

May it be because Alarm and Alarm2 already exist in sensors.yaml as standalone ones?

So you already have sensors in Home Assistant for the two gate switches ?

I deleted dualities, left there template only and still the same error.
So mistake must be somewhere else :frowning:

Hm, I have 2 sensors-Alarm and Alarm2. Both are working separately. It seems to me that I cannot use them together in template. Well, be more specific I am not able to use them as I need.
Please advice.

How does the configuration for those sensors look now?

Finally I did it :sunglasses::bulb::

  - platform: template
    sensors:
      gate:
        friendly_name: "Test"
        value_template: >-
          {% if is_state('sensor.alarm2', 'ON' ) %}
            {% if is_state('sensor.alarm', 'OFF' ) %}
              OPEN
            {% endif %}
          {% elif is_state('sensor.alarm2', 'OFF' ) %}
            {% if is_state('sensor.alarm', 'ON' ) %}
              CLOSE
            {% else %}
               MOVE
            {% endif %}
          {% endif %}

One last thing I need to solve within those sensors is how to achieve their “immediate” reaction on the change. Now I am using short telemetry period ( 10 sec ) but I do not think it is the best solution.

1 Like

How are the sonoffs sending status ? If by MQTT it should be instant.

…and well done on the template ! It can be hard to get your head around.

If I checked sonoff console, sensor connected to GPIO14 of sonoff is publishing MQTT cmnd/ and tele/ but no stat/
stat/ is published by the main switch only.
So far I do not know how to change it.

Regarding template it was was tough way back to school time and force me to refresh programming basis.
I am curious what will be the next challenge :joy: