I searched the community forum for ‘invert binary sensor’ and the commonly suggested solution is to create a template binary_sensor to invert the output of your KNX sensor.
There is also a Feature Request to provide binary_sensors with an invert: true option. You may wish to vote for it.
The reason I asked if you were using MQTT Binary Sensor is because you can invert it by modifying its payload_on and payload_off options.
Where do you define your existing binary sensors? In configuration.yaml under a section called binary_sensor: or in a separate file (like binary_sensors.yaml)?
Not the most elegant solution, but I ended up using the sensor to trigger an input_boolean that way the input_boolean will keep the sensor state after a restart.
You could also use the input_boolean to invert your open / close states.
A package is like combing automations.yaml configuration.yaml groups.yaml for that single subject into a single package.
So you might have packages for heating, door sensors it’s another way to stopping your configuration.yaml and automations.yaml turning into a several thousand line file over time.
You can view my setup in my GitHub, you can see I use a combination of configuration.yaml and automations.yaml along with packages.
The part 1234EE is the RF data received from the door switch. I don’t know how KNX sensor look so you might be able to replace it with:
- alias: master_bedroom_window_open
trigger:
platform: state
entity_id: switch.knx
to: 'on'
action:
service: homeassistant.turn_on
entity_id: input_boolean.master_bedroom_window
If it is inverted you could change
to: ‘on’
to
to: ‘off’
If you can provide what a KNX sensor looks like within HA I can probably give you a better reply how you might be able to adapt my example.
I have a question for you about the KNX binary sensor. This is not related to inverting the state.
Let’s say you open the window being monitored by the KNX binary sensor representing address ‘8/1/14’. Theoretically, the window’s state is ‘activated’. Now what happens if, while the window is still open, you restart Home Assistant? After restarting does Home Assistant report the window is no longer ‘activated’?
I’m asking these questions because I don’t know how KNX works and I’m wondering if the ‘activated’ command is persistent, meaning it is reported for as long as the window is open (or closed), or is momentary, meaning it reports the window’s state to anyone listening but you have to be present and listening to hear it (if you arrive after the event occurred you won’t hear what happened). For MQTT, “momentary” is the default mode of operation and you have to use an option to change the behavior to persistent.
Now what happens if, while the window is still open, you restart Home Assistant?
Let me give you a full insight: When I restart HA all sensors are in an “Off” state, the state they should have when the window is open. When I turn the handle to open the window physically it stays “off”. As soon as I turn the handle to close the window the sensor is going into an “on” state.
Now to your question: When the window is open, is in the “off” state and I restart HA then of course it´s still shown as off (because HA is resetting the status)
The thing is now: as I mentioned in other posts a few times I’m coming from a comercial solution named Symcon. I still have it and use it as some sort of control mechanism (and it was to expensive to get completely rid of it). Symcon is keeping the state of the sensors.
I don’t have the KNX configuration software here so I can’t check it but at least with HA it seems is momentary.