Unable change status name anyway

Tags: #<Tag:0x00007f77ffb92688> #<Tag:0x00007f77ffb92520>

Good morning, I apologize in advance for a topic that has already been here many times, I really read everything a few times but I still can’t find the answer. I installed the xiaomi door open sensor which shows correctly in HA Open and Closed, but now I need to change the sensor status from Open to Close and vice versa.

I tried to add a configuration for this binary sensor in configure.yaml and HA can’t see it. I also tried to change the settings for this sensor here:

Screenshot_2020-02-13 Home Assistant(1)

and that also doesn’t change anything. Tested in each of these places I also changed the name to a different one and the name is visible only until the first change of the sensor status and returns to the one declared here:

I am completely confused because I have not found such a case anywhere with similar symptoms, can anyone cope with it? Perhaps this is a change in concept in the new version?

arch armv7l
dev false
docker true
hassio true
os_name Linux
python_version 3.7.6
version 0.105.3

Best regards

Changes made in the states page are temporary only until the next status update happens.

It is only used for testing triggers and other sensors.

If you want to change the name of a sensor, you need to click the (i) to the left of the sensor name, then click the cog on the top right of the popup. There you can change the name permanently (until you change it later I suppose). I would recommend doing that, especially for this sensor.

If I understand you correctly, you want to invert the states. When it’s reporting closed, you want it to report open?

You’ll have to make a template binary sensor.

binary_sensor:
  - platform: template
    sensors:
      door_sensor:
        friendly_name: "New Sensor"
        device_class: door
        # Want this to be inverse of the real sensor. So, if it reports off, this will return true (on).
        value_template: "{{ is_state('sensor.new_sensor_name', 'off') }}"
        # Also want to keep the same attributes
        attribute_templates:
          battery: "{{ state_attr('sensor.new_sensor_name', 'battery') }}"
          voltage: "{{ state_attr('sensor.new_sensor_name', 'voltage') }}"
          contact: "{{ state_attr('sensor.new_sensor_name', 'contact') }}"
          linkquality: "{{ state_attr('sensor.new_sensor_name', 'linkquality') }}"

Now just use this sensor.door_sensor in place of your other one.

as it a binary_sensor it will change base on what is in the

and format the output with the
device_class:

if you change the “Stan” state off and click “ustaw stan” SET STATE
it will display Closed on the GUI lovelace

then

think of the device_class is the display format
but HA only see a on/off

BUT in saying that automation can be funny somethings

I have this binary_sensor

but if i want the light to come when door open i have this

- id: Front Door Open
  alias: "Front Door Open"
  trigger:
  - entity_id: binary_sensor.front_door
    platform: state
    to: 'on'
  condition:
  - condition: state
    entity_id: sensor.day_night
    state: 'Night'
  action:
    - data:
        entity_id: light.front_door_2
        brightness: 255
      service: light.turn_on

Yep, that’s how binary sensors work. They are only ‘on’ or ‘off’ states. It makes it easy to know the state when you see a binary sensor.

If you want it to actually say ‘Open’ or ‘Closed’, still use a template sensor. Instead, use a normal one, not a binary one (which is only on or off)

sensor:
  - platform: template
    sensors:
      door_sensor:
        friendly_name: "New Sensor"
        device_class: door
        # Want this to be inverse of the real sensor. So, if it reports off, this will return true (on).
        value_template: >-
          {% if is_state('sensor.new_sensor_name', 'on') %}
            open
          {% else %}
            closed
          {% endif %}
        # Also want to keep the same attributes
        attribute_templates:
          battery: "{{ state_attr('sensor.new_sensor_name', 'battery') }}"
          voltage: "{{ state_attr('sensor.new_sensor_name', 'voltage') }}"
          contact: "{{ state_attr('sensor.new_sensor_name', 'contact') }}"
          linkquality: "{{ state_attr('sensor.new_sensor_name', 'linkquality') }}"

Now your new sensor will say ‘open’ or ‘closed’. Again, use this new sensor for your automations.

Like what you have done

but using a device_class in a binary sensor

will change the icon and the display name

OMG, I even don’t know when I’ll reach this state :grimacing: it’s all a little crazy so my brain is slowly boiling :slight_smile:

Do I correctly understand that this is for that based on the PHYSICAL state of the sensor to create a new “virtual” sensor entity, then after that I will create a view in lovelace ??
If so, I did this example in /config/configuration.yaml but I certainly did something stupid because it didn’t show up in current entities:


binary_sensor:
  - platform: template
    sensors:
      door_sensor:
        friendly_name: "Quite_New_Sensor"
        device_class: door
        # Want this to be inverse of the real sensor. So, if it reports off, this will return true (on).
        value_template: "{{ is_state('binary_sensor.0x00158d00044b72dd_contact', 'off') }}"
        # Also want to keep the same attributes
        attribute_templates:
          battery: "{{ state_attr('binary_sensor.0x00158d00044b72dd_contact', 'battery') }}"
          voltage: "{{ state_attr('binary_sensor.0x00158d00044b72dd_contact', 'voltage') }}"
          contact: "{{ state_attr('binary_sensor.0x00158d00044b72dd_contact', 'contact') }}"
          linkquality: "{{ state_attr('binary_sensor.0x00158d00044b72dd_contact', 'linkquality') }}"

:frowning:

I think you’re over thinking it.

A binary sensor is ‘on’ or ‘off’. Always. Writing automations against a binary sensor, you check for ‘on’, or ‘off’.

A regular sensor can be any state at all, even ‘on’ and ‘off’.

The device_class is how Lovelace knows what icon to show and how it interprets the on/off state. But, the true state of the sensor is either ‘on’ or ‘off’.

You aren’t required to create a template sensor for any of these. Your example of checking if the window sensor is ‘on’ isn’t weird to me at all because I know we’re checking the window sensor. We aren’t checking if the window is opened or closed. In fact, the window can be open and the sensor can be ‘off’ if you put a piece of tape over the sensor (push button sensor).

I personally only define the device_class when needed and leave all sensor states alone. The few times I create a template sensor is when I want to convert values to different units, or expose an attribute of one sensor as another sensor.

Jim, don’t be mad at me - I think I understand what you are writing about, but I don’t know how to apply this knowledge, certainly because I have been dealing with HA for only a week and I have missed many lessons. As I wrote I created in configuration.yaml above example nothing happened:

  • the existing description in Lovelace has not changed
  • in lovelace under the button -> sensors I can not see the previously declared device Quite_New_Sensor
  • under configuration -> devices or registration I also don’t see any Quite_New_Sensor

Of course, I tried reboots or to check device removal or adding new cards in Lovelace … sorry :frowning:

HOW CAN I NOT BE MAD?!? :stuck_out_tongue:

lol, I mean…WHY would I be mad? Everyone’s got to learn somewhere! Plus, there is probably a slight language barrier here and I could easily be misinterpreting things!

the existing description in Lovelace has not changed

A new template sensor will not modify any other sensors. They will continue to do whatever they were doing to begin with.

in lovelace under the button -> sensors I can not see the previously declared device Quite_New_Sensor

I’m not sure where you are or where the sensors button is.

Can you open developer tools and click on STATES at the top? Down under Current Entities, try to search for sensor.door_sensor (assuming you copied my code). The friendly_name will be an attribute of that sensor, not the name of the sensor itself.

Actually, wherever you are looking for quote_new_sensor, search for “door_sensor” instead.

The name of the sensor will be this field:

binary_sensor:
  - platform: template
    sensors:
      door_sensor:  <---- Name of the sensor is here!!!

You don’t need to do the last thing you did above - you don’t need to create a sensor at all. You already have a binary_sensor tht works.

All you need to do is just change the device-class of the existing binary_sensor in the customize section of the configuration to “door”

device_class: door

and what should I do with this class? where to find it? I think the whole problem is that no such change in configuration.yaml has any effect on HA…

where to find what? the documentation for the device classes?

otherwise i’m not sure what you’re asking.

my whole life consists of interesting cases, e.g. now - I don’t see any changes in STATES

automation.dimm_off on
automation.swiatlo_off on
binary_sensor.0x00158d00044b72dd_contact on
binary_sensor.updater off
device_tracker.lg_h850 home
light.shelly_shrgbw2_6cf585_1 unavailable
light.shelly_shrgbw2_6cf585_2 unavailable
light.shelly_shrgbw2_6cf585_3 unavailable
light.shelly_shrgbw2_6cf585_4 unavailable
person.jerzy home
person.misiek unknown
scene.d drzwi_gora scening
sensor.0x00158d00044b72dd_battery 100
sensor.0x00158d00044b72dd_linkquality 52
sensor.battery_level 67
sensor.date 2020-02-14
sensor.date_time 2020-02-14, 00:33
sensor.date_time_iso 2020-02-14T00: 33: 00
sensor.date_time_utc 2020-02-13, 23:33
sensor.hacs 2
sensor.internet_time @ 022
sensor.time 00:33
sensor.time_date 00:33, 2/14/2020
sensor.time_utc 23:33
sensor.wifi_connection kuleczka222
sun.sun below_horizon
weather.dom snowy
zone.home zoning

I know that, but whatever I do in the configuration.yaml, I can’t find the result anywhere, for example in Lovelase…

what are you trying to do in configuration.yaml that isn’t changing anything?

also you don’t configure your lovelace UI thru configuration.yaml. you do that either thru the GIU editor or in ui-lovelace.yaml if you are in yaml mode.

if you change the entity device class in the customize section it should reflect that in the UI tho.

I’m trying to change the description of my binary_sensor.0x00158d00044b72dd_contact from off to on or closed or whatever and see it in Lovelace

??? - I don’t know what to say - I don’t understand it at all :frowning:

and this is what is happening but only until the first change of the sensor state, then everything goes back to the previous description, state, etc.

post the contents of your customize section.

or are you changing it in the “configuration->customizations” page?

I tried both solutions but without success :frowning:
here is my sensor states:

binary_sensor.0x00158d00044b72dd_contact	on	battery: 100 voltage: 3105 contact: false linkquality: 47 friendly_name: GERDA_G device_class: door							
sensor.0x00158d00044b72dd_battery	100	battery: 100 voltage: 3105 contact: false linkquality: 47 unit_of_measurement: % friendly_name: GERDA G. device_class: battery							
sensor.0x00158d00044b72dd_linkquality	47	battery: 100 voltage: 3105 contact: false linkquality: 47 unit_of_measurement: lqi friendly_name: GERDA_G icon: mdi:signal							

here is my configuration.yaml

binary_sensor:
  - platform: template
    sensors:
      door_sensor:
        friendly_name: "Quite_New_Sensor"
        device_class: door
        value_template: "{{ is_state('binary_sensor.0x00158d00044b72dd_contact', 'off') }}"
        attribute_templates:
          battery: "{{ state_attr('sensor.0x00158d00044b72dd_battery', 'battery') }}"
          linkquality: "{{ state_attr('sensor.0x00158d00044b72dd_linkquality', 'linkquality') }}"

thank you all for help!

post the code you tried when you tried it in your configuration.yaml.

Just to clarify…

are you just trying to see the state of the binary_sensor in lovelace at al or can you see the state there (as either ‘on’ or ‘off’) but instead you want to see it as “open” or “closed”?

do you have the binary sensor already showing up in lovelace?