I am having issues with using a shell_command to set the state of a sensor (via REST).
My shell_commands.yaml file includes:
set_hue_tap_1_state: curl -X POST -d '{"state":"idle"}' http://127.0.0.1:8123/api/states/sensor.bedroom_switch -H 'Authorization:Bearer SECRET_LONG_LIVED_TOKEN'
I’ve tried a few things:
With and without -H 'Authorization:Bearer SECRET_LONG_LIVED_TOKEN'.
With loopback IP, local IP and duckdns address.
Using either a state that “exists” (it shows 1_click, 2_click, etc. I have tried one like this.) and what I’d actually prefer (some dummy state, e.g. “idle”).
And nothing seems to work.
I want to use this to set the state of a Hue Tap remote to “idle” after each click. Otherwise, I can’t click the same button twice, and have it register (and I use a few of them as “toggle” buttons, so I do click the same button repeatedly).
Not sure why you have to change the state of a sensor “manually.” I would think you shouldn’t have to do that. But I’m not familiar with the type of sensor you’re using.
Having said that, if you just want to change a state you could do it via a python_script, which doesn’t require having to go “out and back in” of HA via the network. E.g.:
The sensor is actually a remote (Hue Tap). I need to set the state because if I press button 1, then I can fire an automation because it changes to state: 1_click. If I click button 1 again, nothing changes, so nothing happens.
So I want each automation to do its thing, and then set the state to a “dummy” state, so it will register state change if I press the same button again.
I tested the python script, and I think it has something to do with the actual device, maybe not the shell_script or python script. I see the change happen, but with less than a second, it changes back to the previous state (this doesn’t happen if I try the same script for other sensors.)
The curl works fine, I just tested it with a light. It changes the state. It seems like it’s a thing with the Hue component. I created an issue.
I ended up moving it to AppDaemon instead. This script works, it registers the same button pressed several times sequentially.
(If I changed the state to idle using AppDaemon script, then I could see the state change in states, but it would automatically change back to e.g. 1_click, and then I noticed that it registered the clicks without the idle state)
But again, if you “just” need a curl command with bearer, then the above works (just put your entity and state as needed).