Add values to my template sensor?

is it possible to add this? armed_home to my template sensor?

  - platform: template
    sensors:
      mqtt_ring_alarm2:
        friendly_name: "Ring Alarm MQTT Service"
        value_template: "{% if is_state('alarm_control_panel.ring_alarm', 'disarmed') %}on{% else %}off{% endif %}"

if it’s disarmed or armed its on else its off… i tried doing it the other way, but the ring mqtt would not show up if it’s “Off” by deseign

  - platform: template
    sensors:
      mqtt_ring_alarm2:
        friendly_name: "Ring Alarm MQTT Service"
        value_template: "{{ 'on' if is_state('alarm_control_panel.ring_alarm', 'disarmed') else 'off' }}"

If it’s Template Binary Sensor, you can reduce the template to:

       value_template: "{{ is_state('alarm_control_panel.ring_alarm', 'disarmed') }}"

id like to know if it’s on or off…

If I read it right then this is what you are wanting:

  - platform: template
    sensors:
      mqtt_ring_alarm2:
        friendly_name: "Ring Alarm MQTT Service"
        value_template: >
          {% if is_state('alarm_control_panel.ring_alarm', 'disarmed') or is_state('alarm_control_panel.ring_alarm', 'armed_home') %}
            on
          {% else %}
            off
          {% endif %}
1 Like

That’s precisely what a Template Binary Sensor reports.

The first paragraph of its documentation:

The template platform supports binary sensors which get their values from other entities. The state of a Template Binary Sensor can only be on or off .

thanks for your help! now to create an automation to turn the service on if its off…

I missed the part about you wanting it to check for either of two states: disarmed or armed_home.

In that case, I still recommend a Template Binary Sensor because you stated all you want it to report is either on or off. It allows for an even simpler template.

  - platform: template
    sensors:
      mqtt_ring_alarm2:
        friendly_name: "Ring Alarm MQTT Service"
        value_template: "{{ is_state('alarm_control_panel.ring_alarm', 'disarmed') or is_state('alarm_control_panel.ring_alarm', 'armed_home') }}"

how does the template state if its on or off?

By default a binary sensor is either on or off. it can’t have any other state by definition. If the value template evaluates to true then the binary sensor is ‘on’ otherwise it’s ‘off’.

@123’s sensor is cleaner if that is the only possible states you want for your sensor. If you need any other state (other than on or off) then you have to use a non-binary sensor.

Good question! It’s because when the template is evaluated it results in either True or False.

You can prove it to yourself by pasting the following template into Home Assistant’s Template Editor.

{{ is_state('alarm_control_panel.ring_alarm', 'disarmed') or is_state('alarm_control_panel.ring_alarm', 'armed_home') }}

Binary sensors represents True as on and False as off.

You can optionally set the binary_sensor’s device_class and, in the UI, it will show different states like open/closed, detected/clear, wet/dry, etc.


thanks! apprecate the help