ugh, very frustrating that this isnt possible without using a hack (AppDeamon) and not available within standard configs.
I think a switch template would work:
- platform: template
switches:
skylight:
value_template: "{{ is_state('sensor.skylight', 'on') }}"
turn_on:
service: switch.turn_on
data:
entity_id: switch.skylight_open
turn_off:
service: switch.turn_on
data:
entity_id: switch.skylight_close
I believe the state of the switch does not trigger the actions, only the actions in the UI trigger the actions.
Well, in all fairness, what we want to do is sort of a hack anyway - updating the internal state without telling the external component about it.
If you don’t want to use appdaemon, you can do it from an automation by calling the REST API.
What exactly is the wall remote in this case and where does it get its state from? This sounds like it could just be an issue in the way the wall remote is set up. Perhaps something like a template switch like @petro mentioned could work.
So the you can do local api calls through HA automation configs?
Hey - sorry to bring my own problem to this post… but I’m having an issue with the state of an input_boolean and came across this thread. It seems like the solution here could maybe work for me. Would you mind seeing if you have any ideas in regards to my issue? Performing switch/input_boolean "off action" when hass thinks it is already off. Broadlink
Thanks. I’m gonna try this. Hopefully it works for my problem of the climate component air conditioner being turned on/off outside of HA.
For future readers looking for another option, I solved this using Node-RED. Under “manage palettes” I installed the node-red-contrib-hass
package. It contains the hass-post
node which calls the api/states
API endpoint to set state on an entity in home assistant.
I’m also using a change
node to set msg.payload
to {"state": "off","attributes": {"assumed_state": true}}
(or state could be “on”) and to set msg.entityid
to switch.switch_name
. Those values are passed into the hass-post
node and the API is called as expected. Note that you don’t need multiple hass-post
nodes. You could have multiple change
nodes passing values into the same hass-post
node (leave the Entity ID field blank in the hass-post
node since that value comes from the change
node).
Here’s a screenshot of my node red flow: https://imgur.com/a/dwpJwuS
Explanation: I have a z-wave plug that is also a power meter. Based on the wattage reported by the plug, I set the state on various switches that control my window evaporative cooler (via a Broadlink RM mini 3). This gives Home Assistant feedback as to what mode the cooler is operating in. So now I can change the fan or pump setting using the cooler’s IR remote and home assistant will know that I changed something. This also makes home assistant more fool-proof so it doesn’t get out of sync with the state of the cooler, which can happen if the IR signal from the Broadlink doesn’t get picked up by the cooler, for example.
that doesnt do what this topic is about, unless something hass changed in HA.
if you change a switch with API from on to off then HA sends the off command to the device.
you set the device to some state and then send a signal to HA to change it.
after that HA sends the change also, but you dont notice that.
your switch gets turned off twice, but for you thats no problem.
people who have toggle switches would have trouble with it.
If I go to the HA “States” page, I can change the state of a switch to “off”, but that doesn’t actually call the “turn_off” action on the switch, right? Isn’t that what this topic is about? If I use a curl command like this:
curl -X POST -H "Content-Type: application/json" -d "{\"state\": \"off\"}" http://HA_IP_ADDR:8123/api/states/switch.switch_name?api_password=PASSWORD
That will do the same thing, right? It changes the state, but I’m not seeing the switch action actually be called (my Broadlink mini doesn’t send an IR command to the cooler). I tried the same curl command with a z-wave light switch entity and it is changing the state of the entity does not turn the light on or off.
I’m on HA version 0.70.1. Are you on a different version that behaves differently?
in some cases it seems to do in others not.
but in many cases that just doesnt work.
if i use set_state in appdaemon (which is actually the same as you do) for a switch then it changes the state from the switch for a second and then it turns back. unless the state is changed for the component that is connected to it.
changing the state though api is just buggy. for sensors it works as it should, but for switches it was always buggy. at least for the switch types i own and can test.
Works for me.
for a lot of other cases also.
if i read back it also worked for others with set_state.
but it seems that you take an "unusual"path and thats why you need the set_state.
normally it would be:
something changes > automation (in HA, nodered or AD) gets triggered > HA changes something
you do
something changes > automation changes something and tells HA what has changed.
that takes out a functionality from HA and makes HA just a dashboard.
nothing wrong with that, but if you dont do that everywhere you could get lost when the amount of automations and settings get big.
and i dont see how it makes HA more foolproof, because if the IR command from the broadlink doesnt get picked up there is no trigger to change the states back. unless you check the states based on time. but if you do that, it isnt the set_state that makes it more foolproof, but your double check.
Did this work for your AC unit. I have the same problem. I have an input_boolean associated with Alexa and tied to automate my AC with the zxt-120.
It works fine but if I turn on with HA and then turn off with the remote then Asking Alexa to turn on no longer works because HA thinks it is on already.
I really just want a stateless switch, this is how I solved the same issue in SmartThings but it doesn’t seem to exist in HA.
I have tested if I set state using Curl to “NA” or anything other then on or off, after I issue the turn_on or turn_off then the next on or off will work.
I am just curious if you found a better way since it seems you had the exact same issue.
Yes it worked. However either the hass.io upgrade or switching over to unufi router has made it so ha gets invalid Auth error when i try this now.
OK thanks for reply. I guess you have not found a new solution? I wrote a script called stateless_switch which I call after issuing a turn_on or turn_off. It sets the state from on/off → “stateless”. It makes the UI get a little weird but I will hide the ui component anyway since it’s just for voice control. It’s working fine.
Did all /api calls stop working with hass.io or is it just changing state is no longer allowed? I hope they don’t remove this api feature. It’s the only good way I have found to hack around the issue.
I really don’t understand the point of “assumed_state”. It creates what looks like discreet on and off ui components but issuing a discreet request when the state is already set doesn’t fire triggers. So I don’t see how this is ever useful.
I see two ideal solutions for this. Both of which exist on the platform I am coming from.
- Add a force state change service. so instead of calling input_boolean.turn_on service you call input_boolean.turn_on_force_state_change or something better named.
- Alter assumed_state switches and input_booleans to always issue a state change when a discreet on or off is called. This was the intuitive behavior I was expecting. It just doesn’t work the way I would expect. If the UI state is “assumed” then why would you not issue the command to fire the device just because the state is the same as the existing state. The way it is now any incorrect “assumed” state causes the device to stop working.
Glad I found a hack for now. Hope it doesn’t get broken too soon
the curl command above works.
but for some reason my rest_command api call stopped working.
you should add a door sensor to your aircon vent.
use that to update the state of the aircon when it is turned on / off via remote control.
Cool idea. Pun intended. Do you have one you recommend. It should be light and of course integrate with HA well. I am finding a lot of my zwave devices I am porting over from my old system don’t work 100% on HA.
Hello everyone! I was following this thread trying to find a solution for a similar problem that I have, that I hope any of you can help me to solve it. Given this post is from Aug, maybe any of you already found a solution. Believe me that I have searched a lot in here and took lot of examples from this community but I could’t make it work. Maybe because it is impossible.
Basically what I want to do is synchronising a Broadlink Switch, which we know it is stateless, with my harmony device.
So, the switch turns ON and OFF my tv through Broadlink hub. And in the other hand I have my harmony that also turns on my TV with a select_option.
Therefore I want to change the Broadlink switch state from OFF to ON and from OFF to ON, when I turned ON the TV using Harmony. Why? Basically sometimes Harmony gets down so using Broadlink I can count with backup method for handling the TV.
In the following example, the switch is not only changing the state, it is also sending the IR frequency to the TV. I just want to change its state.
### Start Harmony Activity
- alias: Start Harmony Activity
trigger:
- platform: state
entity_id: input_select.harmony
action:
- service: remote.turn_on
entity_id: remote.harmony_hub
data_template:
activity: >
{% if is_state("input_select.harmony", "Watch Tv") %}
35077645
{% elif is_state("input_select.harmony", "Watch Netflix") %}
35078071
{% else %}
{% endif %}
Then the event that changes the input_select
- alias: Update Harmony input select
trigger:
- platform: state
entity_id: remote.harmony_hub
action:
- service: input_select.select_option
data_template:
entity_id: input_select.harmony
option: "{{ states.remote.harmony_hub.attributes.current_activity }}"
Here below is what I’m trying. Basically capturing the input value and if its watch tv, I wanted to change the status of the switchtv without sending the command.
I know this script fails and it is because the service is incorrect. Do anyone know a way to do it? Is there a service that allows me to change the state of a switch?
Thank you a lot!
- alias: Harmony Changed State
trigger:
- platform: state
entity_id: input_select.harmony
action:
service: homeassistant.turn_on
data_template:
entity_id: switch.tv
state: >
{% if is_state("input_select.harmony", "Watch TV") %}
on
{% else %}
{% endif %}