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:
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
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.
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.
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') }}"
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
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!!!
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.
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?