home-assistant-ecosystem / home-assistant-cli

:computer: Command-line tool for Home Assistant
Other
446 stars 69 forks source link

Pass RGB parameters to color bulb? #345

Open jbrepogmailcom opened 4 years ago

jbrepogmailcom commented 4 years ago

Hello, is this possible with hass-cli? I can start a scene that I previously defined in Smart Life, but that way it only allows to set one predefined color. I would like to set various colors by hass-cli.

(IFTTT used to do that, at least for basic colors red, blue, orange, yellow, white, green... But is not integrated with Smart Life anymore)

Thanks, Jan

bpsib commented 4 years ago

Can someone explain how to do this? I have tried hass-cli service call homeassistant.toggle --arguments entity_id=light.055667caab5065b --arguments rgb_color="[0, 0, 255]" but get error: ValueError: dictionary update sequence element #1 has length 1; 2 is required

bpsib commented 4 years ago

So I have given up on this and made my own solution using the REST API and curl. I have made my own script for changing the color and have the token saved in a file called hatoken. Replace localhost with your IP/domain if necessary.

curl -X POST -H "Authorization: Bearer $(cat ~/hatoken)"  \
-H "Content-Type: application/json" -d '{"entity_id": "'"$1"'", "rgb_color": ['$2', '$3', '$4']}'  \
http://localhost:8123/api/services/light/turn_on

Example: ./lightrgb.sh light.mylightid 0 0 255 Sets the light to blue.

P.S. Smart Life is back on IFTTT but using it to set the color is very temperamental. Sometimes it works but other times it just goes on the set color for a split second then reverts back. A very annoying bug with IFTTT.