Can I change the displayed state of the sensor?

For example, I setup AlarmDecoder and it created sensor.alarm_panel_display. When it is ready to arm, the status is “DISARMED CHIME Ready to Arm”. Can I change it to “Ready to Arm”?

Also, if the door is opened, the status is “Fault 01”. Can I change it to something like “Zone 1 is not ready”?

The second door is opened and it shows the status “Fault 2”. Can I change it to “Zone 2 is not ready”?

Etc…

Thank you.

Hi @onlize,

You can create sensor template that its value will be based on those cases.
Template value should look like:
value_template: >-
{% if is_state(‘sensor.somename’, ‘Fault 01’) %}
Zone 1 is not ready
{% elif is_state(‘sensor.somename’, ‘Fault 02’) %}
Zone 2 is not ready
{% else %}
Armed
{% endif %}

Elad

Hi @bar, thank you for your reply.

The sensor does not exist. It is created automatically when I add zone for alarmdecoder. How can I add something to the sensor that does not exist in configuraton.yaml file?

Just to understand, you have another component that generates that sensor on load, right?
If that’s the case, do you know the name of that sensor?

Yes, I setup AlarmDecoder with multiple zones. It created multiple binary_sensors for zones and it created sensor.alarm_panel_display. I need to change the status of this sensor.

I set it up as described here:

Great, then you need to extract the name of the sensor that it creates, create sensor template based on that sensor’s state and it will work.

I have few template sensors that work the same with different components that generate other sensors,
Try it, if you have any issues post the error here

What do you mean “extract the name of the sensor that it creates”?

It creates sensor with the name sensor.alarm_panel_display. Is this the name that I need to use?

Yes, adjust the value_template as written above with that sensor

Thank you, I will try it in the morning.

Something does not work. I used this code:

      alarm_panel_display_status:
        friendly_name: 'Alarm Panel Display'
        value_template: >-
          {% if is_state('sensor.alarm_panel_display', 'FAULT 01') %}
            Zone 1 is not ready
          {% elif is_state('sensor.alarm_panel_display', 'Fault 02') %}
            Zone 2 is not ready
          {% else %}
            {{ states('sensor.alarm_panel_display') }}
          {% endif %}

When I open the door for the Zone 1, it displays “FAULT 01”. Any ideas what is wrong with my code?

Which sensor are you looking at to see “fault 01”? the old sensor or the new sensor you just created?

Are you looking at the status of “sensor.alarm_panel_display_status” or “sensor.alarm_panel_display”?

the old one will still show the old status (fault 01). the new one should show “Zone 1 is not ready”.

Edit: I just noticed the different cases of the status to test for in your template. The template is case sensitive. “FAULT 01” is not the same as “Fault 01”.

Both sensors show me “FAULT 01”.
I also changed and used “FAULT 01” in template, but it still does not work.

There is something in the template that is causing the first two statements to not evaluate as true so the ‘else’ statement gets executed.

Have you ever used the template dev tool? You should probably use that to figure out why you’re first statement isn’t properly evaluating. once you figure that out then the rest should fall into place.

I do not see the reason not to evaluate that. I copied and pasted the code that I use.

I do not know what is template dev tool, so I guess I have not used it. Give me a link where I can read about that and I will try to figure it out.

Your template isn’t evaluating properly because your state is getting caught by the if statements. This will result in your template returning the last value that it was set to. This is probably why it still reads the same value.

Please paste the code:

{{ states('sensor.alarm_panel_display') }}

into the template editor and see the result with door 1 open, door 2 open, and closed.

To make it easier, I used the following code on that page:

          {% if is_state('sensor.alarm_panel_display', 'FAULT 05') %}
            Zone 1 is not ready
          {% else %}
            {{ states('sensor.alarm_panel_display') }}
          {% endif %}

When I open the door, the output is “FAULT 05”

can you post your whole sensor section in your config? Also, take a picture of this page, with the sensor in question in the display (when the door is open):

If you have custom-ui installed you can change any statedisplay into whatever you want, without having to create any template sensor.

sensor.tarief_daystart:
  templates:
    icon: >
      if (state === '1') return 'mdi:numeric-1-box-multiple-outline';
      if (state === '2') return 'mdi:numeric-2-box-multiple-outline';
      return 'mdi:fire';
    theme: >
      if (state === '1') return 'green';
      return 'orange';
    _stateDisplay: >
      if (state === '1') return 'Laag';
      return 'Hoog';

In this case see the last _stateDisplay. simply fill in the actual state between the quotes, and add what you want it to display after the return . Note: this doesnt actually change the state, only what is displayed in the frontend.

see:
32 :wink:

in your case:

    _stateDisplay: >
      if (state === 'DISARMED CHIME Ready to Arm') return 'Ready to Arm';
      return  state;

Sorry, I do not know what is the State Dispaly.

Here is the code that I use:

  - platform: template
    sensors:
      alarm_panel_display_status:
        friendly_name: 'Alarm Panel Display'
        value_template: >-
          {% if is_state('sensor.alarm_panel_display', 'FAULT 05') %}
            Zone 1 is not ready
          {% elif is_state('sensor.alarm_panel_display', 'FAULT 02') %}
            Zone 2 is not ready
          {% else %}
            {{ states('sensor.alarm_panel_display') }}
          {% endif %}

Here is the picture that includes both sensor when that zone is opened:

Thank you.

_stateDisplay is the way the state is displayed …:wink: And the answer to your original question.

You now make an extra template sensor, which is in fact unnecessary when you could use customize.