Hi everyone! I am just getting started with Home Assistant and am using it to automate a few lights and switches. One of the ways I want to automate a coupe lights is by using my Google Home to turn on, off, and dim lights. I am using IFTTT to listen for a Google Assistant phrase (“Turn on the dining room light”) which will then send a POST request to the Home assistant API.
So far, everything is working great and I am able to turn on, off, and dim the lights! My only concern is dimming. I have to specify the brightness as a number between 0 to 255. While it works, this is not very intuitive.
I would like to be able to specify a number from 0 to 100 and have it act accordingly. My first (and only) thought was to have IFTTT listen for a number then multiple it by 2.55 but IFTTT can’t do math. Any ideas?
Handle it on the HA side. Rather than call the ligh.turn_on service, create a script that you use instead that will do your calculation and then call the service with the correct value.
Though it took a little more work than I would have liked, that absolutely did the trick. Here is what I had that didn’t work and what I now have that does (for anyone reading this in the future).
I have an IFTTT applet (Google Assistant phrase with a number) send a post request whose body contains JSON data of the desired entity and brightness. The trigger phrase was “set the light to #”
JSON body
{“entity_id”: “light.ge_12724_3way_dimmer_switch_level_5_0”,“brightness”:"{{NumberField}}"}
The above works just fine if you want to use a number between 0 and 255, which I did not. Saying “set the light to 50%” is much more natural than “set the light to 128.”
Scripting to the rescue! In my configuration.yaml I added the following:
customize (to hide the script from appearing on the home page)
set_light_brightness_by_percent:
alias: Set light brightness by percent
sequence:
- service: homeassistant.turn_on
data_template:
entity_id: '{{ entity_id }}'
brightness: '{{ brightness | multiply(2.55) | int }}'
Then it was a simple matter of updating my IFTTT applet to the phrase “set the light to # %” (notice the added percent sign) and changing the post URL to the following: