Hi,
I’ve been futzing about with this for about 6 months now, read what I think is relevant posts:
and the command_line documentation
- but i still can’t get it to work.
I have verified my code for echo’ing 0 or 1 working fine in a terminal, and even on the openssh terminal in hassio.
all i want is for state to report correctly on and off, no matter what i do it seems to either set the state to on, or off and stay on that state and not reflect what the device actually is.
to be clear, this is a old, abandoned product that i love called the moorescloud holiday, what i’ve done thus far has technically integrated it in homekit due to the bridge, so leaps and bounds, but the state is always weird.
https://twitter.com/posty/status/1469787903840514050?s=20&t=QF6eXKovQgI2dEBqCJOBqQ
the code is pretty simple, it returns a json string, but of rgb values. i’m keeping it simple at this stage and just trying to turn “on” and “off” values.
I actually asked Franck Nijhof if he’d consider developing an integration for me (paid of course!) but he wouldn’t.
So here i am, junior systems admin trying to learn this.
Anyway - here’s the code:
#test config for holiday
switch:
- platform: command_line
switches:
lounge_holiday:
command_on: "/usr/bin/curl -X PUT -d '{ \"lights\": [ \"#ffcb4d\", \"#ff884d\", \"#ff974d\", \"#ffa64d\", \"#ffb54d\",
\"#ffa64d\", \"#ff974d\", \"#ff884d\", \"#ffcb4d\", \"#ff6c4d\",
\"#ffcb4d\", \"#ff884d\",\"#ff974d\", \"#ffa64d\", \"#ffb54d\",
\"#ffa64d\",\"#ff974d\", \"#ff884d\", \"#ffcb4d\", \"#ff6c4d\",
\"#ffcb4d\", \"#ff884d\",\"#ff974d\", \"#ffa64d\", \"#ffb54d\",
\"#ffa64d\",\"#ff974d\", \"#ff884d\", \"#ffcb4d\", \"#ff6c4d\",
\"#ffcb4d\", \"#ff884d\",\"#ff974d\", \"#ffa64d\", \"#ffb54d\",
\"#ffa64d\",\"#ff974d\", \"#ff884d\", \"#ffcb4d\", \"#ff6c4d\",
\"#ffcb4d\", \"#ff884d\",\"#ff974d\", \"#ffa64d\", \"#ffb54d\",
\"#ffa64d\",\"#ff974d\", \"#ff884d\", \"#ffcb4d\", \"#ff6c4d\" ] }' http://192.168.1.204/iotas/0.1/device/moorescloud.holiday/localhost/setlights"
command_off: "/usr/bin/curl -X PUT -d '{ \"lights\": [ \"#000000\", \"#000000\", \"#000000\", \"#000000\", \"#000000\",
\"#000000\", \"#000000\", \"#000000\", \"#000000\", \"#000000\",
\"#000000\", \"#000000\", \"#000000\", \"#000000\", \"#000000\",
\"#000000\", \"#000000\", \"#000000\", \"#000000\", \"#000000\",
\"#000000\", \"#000000\", \"#000000\", \"#000000\", \"#000000\",
\"#000000\", \"#000000\", \"#000000\", \"#000000\", \"#000000\",
\"#000000\", \"#000000\", \"#000000\", \"#000000\", \"#000000\",
\"#000000\", \"#000000\", \"#000000\", \"#000000\", \"#000000\",
\"#000000\", \"#000000\", \"#000000\", \"#000000\", \"#000000\",
\"#000000\", \"#000000\", \"#000000\", \"#000000\", \"#000000\" ] }' http://192.168.1.204/iotas/0.1/device/moorescloud.holiday/localhost/setlights"
command_state: hostname="192.168.1.204"; status=$(curl --silent -X GET http://${hostname}/device/light/value); if [[ $status =~ [1-9] ]]; then echo 0; else echo 1; fi
#value_template: '{{ value == "1" }}'
yes i turned value template off because that appeared to make it worse.
i originally was using ‘exit’ and ‘exit 1’ instead of echo’s because of my interpretation of the phrase ‘return code’ - that still worked by the way, but the other comment seems to go for echo
any help appreciated - i’d love to make a full featured integration for this, but for now on and off will suffice, but correct state is needed.