Change Sensor State Display

I don’t think this is an Insteon issue, although it involves an Insteon device.

I have a garage door opener that includes a sensor to track if the door is open or closed. I have two issues with this. The first one is important and I really want to get it fixed. The other would be nice to fix, but isn’t as confusing or critical. Here’s the device info on my iPhone screenshot:

  1. My biggest problem is the 2nd entity: It says “Open” when the door is closed and, of course, vice-versa. I’m guessing this maybe a N/O vs. N/C switch issue - maybe HA or something along the way doesn’t realize things are reversed.

How can I reverse this so it reads “Closed” when it now reads “Open?” (And, of course, so it reads “Open” when it now reads “Closed.”)

  1. A minor point is the switch. When I activate it for opening or closing, the switch control goes to “On,” then resets to “Off.” I understand what’s going on and why it does this, but is there a control I can display that would be more fitting? And, if so, how would I change that?

Addition - thought it best to put this as a separate post.

Apparently it does matter that it’s Insteon. Insteon uses a json file for configuration issue. I have found this thread about how to reverse the state of a binary switch. However I’m not clear how to link a sensor I create to the Insteon one and if there is a way to make it show up as an entity in the specified device.

  1. I just answered a question here, that can be used in your sitation too.
    Can I change the state to custom? - #2 by WallyR

  2. This is probably not a switch, since you can not really stop the garage opener if you clicked it.
    This is more like a sensor.
    You can rewrite it like in answer 1 to something that makes sense, like idle and working.

I’m copying the code from your other answer here. I thought about replying in that thread, but when I look at your code, I think dealing with a sensor from the Insteon integration is an issue - not a tough one, but one I’m not sure how to solve, since I’m not familiar with the related parts of HA and the configurations and integrations.

sensor chairs:
  - platform: template
    sensors:
      chair_1:
        friendly_name: "Chair 1 presence detection"
        value_template: >-
          {% if (states('sensor.chair1') >= 50) %}
              no seat
          {% else %}
              seat
          {% endif %}
        icon_template:
          {% if (states('sensor.chair1') >= 50) %}
              mdi:block-helper
          {% else %}
              mdi:mdi-chair-rolling
          {% endif %}

I get that you’re reading ‘sensor.chair1’, but when I look in configuration.yaml, I see no reference to the entity (or the device it’s in) within that file. I don’t see another file that I can easily identify as a configuration file that lists all my sensors. Also, is there a way to include the sensor this creates in the list of entities in the garage door opener device?

(In fact, no sensors or controls are listed in configuration.yaml, so I suspect I’m missing something about where all that information for Insteon, Z-Wave, and other integrations are stored.)

You are not missing anything.
configuration.yaml is only holding parts of the configurations. Most of the stuff is now in GUI setups.

Use Developer Tools in the left sidebar to get the sensor data from your insteon
Then use that in the template and put that template in your configuration.yaml file.

Okay, I copied and pasted and put this in sensors.yaml and included it in configuration.yaml. I’m using the file editor plugin to work on it and I get an error message from it. Here’s what I have pasted in:

sensor garage_door:
  - platform: template
    sensors:
      garage_door:
        friendly_name: "House Garage door condition"
        value_template: >-
          {% if (states('binary_sensor.i_o_linc_48_8a_c4_sensor') >= 50) %}
              no seat
          {% else %}
              seat
          {% endif %}
        icon_template:
          {% if (states('binary_sensor.i_o_linc_48_8a_c4_sensor') >= 50) %}
              mdi:block-helper
          {% else %}
              mdi:mdi-chair-rolling
          {% endif %}

At this point I changed very little. I saved it when I got up for a few minutes and I got an error:

missed comma between flow collection entries at line 13, column 12:
              {% if (states('binary_sensor.i_o_ ... 
               ^

After seeing that, I deleted that text and pasted in the original configuration and got the same error on saving.

This error could be from an earlier part of the config, where a tag is unclosed.
You need to paste more of your config before this section for us to see the error.

D’oh!

I should know that - been so absorbed in some other issues (repairing damage from two 100 year flood events in one day back in August!) that I guess I’m not thinking with my programming hat on right now.

I’m going to experiment with that and see what I can work out.

I’m also having problems with including a file. My thought was that if I put the extra config I’m working with in a separate file, and it’s not working, I can just comment out the one include line in configuration.yaml to exclude it so I can restart HA if I have to. But it seems I just can’t get the include statement to work - even when the file I’m including is nothing but comments

I’m using:

inverter: !include inverters.yaml

The file inverters.yaml is in the same directory as configuration.yaml and even when every line in it starts with a hash mark ("#"), I still get errors.

I’m going to be going through this to see if it could be something else I can catch, but for now, this is my entire configuration.yaml:

# Configure a default setup of Home Assistant (frontend, api, etc)
default_config:

# Text to speech
tts:
  - platform: google_translate

sensor garage_door:
  - platform: template
    sensors:
      garage_door:
        friendly_name: "House Garage door condition"
        value_template: >-
          {% if (states('binary_sensor.i_o_linc_48_8a_c4_sensor') >= 50) %}
              no seat
          {% else %}
              seat
          {% endif %}
        icon_template:
          {% if (states('binary_sensor.i_o_linc_48_8a_c4_sensor') >= 50) %}
              mdi:block-helper
          {% else %}
              mdi:mdi-chair-rolling
          {% endif %}

group: !include groups.yaml
automation: !include automations.yaml
script: !include scripts.yaml
scene: !include scenes.yaml
#inverter: !include inverters.yaml

In the File Editor, everything from the “>-” to the first {% endif %} below it is green. When I searched for “yaml comments,” I saw only the hash mark being used for starting a comment. So I’m wondering if that could be an issue - is there a typo there?

You are missing >- in your value template

I see I missed it too in the original post. Sorry! :slight_smile:

Where in the value template? There’s one there, on the line that starts the value_template. Is there another one required, or did you mean in the icon_template?

I meant the icon template.
Just got out of bed. DOH! :smiley:

And I’m just ready to go to bed! :wink:

And I also just got it to restart and was looking it over and realized the other entity on this device, the actual switch, and the sensor, are both showing unavailable.Now I have THAT to troubleshoot before getting back to this. Great fun, that’s gonna be.

(I used to use an ISY-994i and it was on that system and never showed unavailable. It’s Insteon, so I went out of my way to make sure I’m using a PLM that plugs in to the wall so all my Insteon devices can communicate over the power lines just to avoid things like this!)

Hi there,

Sorry to bother, but now that Insteon went belly up and their app is useless, I’ve had to dive into Home Assistant and the Insteon integration.

I’m having the exact same 2 issues with the sensor reading the opposite state, and also the switch vs. a toggle button.

The opener works OK, but it’s kind of convoluted since the sensor state is inverted. Any suggestions you have would be appreciated…

– R Carlson MD

You can read about Template

The general idea is to make a sensor from other sensor values.
You can start by adding this to your configuration.yaml file and then correct the sensor and switch names.

sensor new_insteon:
  - platform: template
    sensors:
      garage_door:
        friendly_name: "New Garage Door Sensor"
        value_template: >-
          {% if (states('sensor.old_garage_door')=='open' and states('switch.old_garage_door')=='off') %}
              closed
          {% elif (states('sensor.old_garage_door')=='open' and states('switch.old_garage_door')=='on') %}
              opening
          {% elif (states('sensor.old_garage_door')=='closed' and states('switch.old_garage_door')=='off') %}
              open
          {% elif (states('sensor.old_garage_door')=='closed' and states('switch.old_garage_door')=='on') %}
              closing
          {% else %}
              unknown
          {% endif %}
        icon_template: >-
          {% if (states('sensor.old_garage_door')=='open' and states('switch.old_garage_door')=='off') %}
              mdi:garage
          {% elif (states('sensor.old_garage_door')=='open' and states('switch.old_garage_door')=='on') %}
              mdi:garage-alert
          {% elif (states('sensor.old_garage_door')=='closed' and states('switch.old_garage_door')=='off') %}
              mdi:garage-open
          {% elif (states('sensor.old_garage_door')=='closed' and states('switch.old_garage_door')=='on') %}
              mdi:garage-alert
          {% else %}
              mdi:help
          {% endif %}

Since I do not have an Insteon device, then I can not test it myself, so I am not sure if the values are correct and I am really unsure how the sensor and switch react to extra activations when one activation isn’t completed yet (= switch is still in on state).