ixica9790
(Charly Andrey)
April 20, 2022, 5:55am
1
Hello!
I would like to build a sort of wifi remote control with an Esp32 (and espHome).
I am using a potentiometer with adc on the esp, I get the value in HA as a sensor, this works fine.
But I want to use the value of the pot to control for exemple the brightness of a light that is connected to HA like a PhilipsHue bulb, or the color (RGB if I have 3 pot for exemple), or the speed of an fastLed effect (adressable led strip).
Is that possible? Can I do that in an automation or a script? If that is possible could someone tell me how to proceed?
Thank you
zoogara
(Daryl)
April 20, 2022, 7:36am
2
See this post which has most of what you need.
Hey,
so I got an illuminance sensor outdoors and some lamps indoors. As the brightness changes I want to adjust my lamps so that if it’s 1800lx outside the brightness should be set to 0 and with an illuminance of 15lx they should be at max brightness (255).
The mathematical operation would be y(br) = -0.143 * x(lx) + 257.143.
One lamp got the entity id light.deckenlampe and the illuminance sensor sensor.illuminance_b.
How could I turn this into a template? It’s my first time working with tem…
You will need an automation to call the turn_on service, just template the brightness using the value of your sensor, making sure it falls in the range of 1-255.
Edit: You can use a single turn_on automation to control your light to be on or off. Just trigger the automation with a change in sensor value, and make it be in the range 0-255. A brightness of zero turns the light off (even though you are calling light.turn_on).
ixica9790
(Charly Andrey)
April 20, 2022, 8:21am
3
Thank you very much! I’ll try.
ixica9790
(Charly Andrey)
April 21, 2022, 5:52am
4
Hello,
I tried this sketch in a script but I get an error.
“light.cuisine” is the light I want to control and “sensor.potentiometre” is my pot value.
Sketch:
alias: potentiometre to control brightness
service: light.turn_on
target:
entity_id: light.cuisine
data:
brightness: '{{ states(''sensor.potentiometre'') }}'
Error:
Key malformed: invalid slug L (try l)
It’s my first time playing with variables in HA so I’m a noobie
Thanks for help
zoogara
(Daryl)
April 21, 2022, 6:02am
5
I think you have got it confused with your quotes.
Try like this:
alias: potentiometre to control brightness
service: light.turn_on
target:
entity_id: light.cuisine
data:
brightness: "{{ states('sensor.potentiometre') }}"
You have used two single quotation marks instead of the double quote mark.
zoogara
(Daryl)
April 21, 2022, 6:05am
6
Also you can test your templates in Developer Tools (the little hammer on the toolbar, then under the Template tab). If you paste "{{ states('sensor.potentiometre') }}"
into there it should display the value of the sensor.
ixica9790
(Charly Andrey)
April 25, 2022, 4:13pm
7
Yes I got a bit confused I don’t really know what i’m doing with this sketch
I’ve tried with your sketch and I got this error:
Message malformed: expected float for dictionary value @ data['brightness_pct]
By the way I’ve used “brightness_pct” because my value goes between 0 and 100
I think that my value is not the good variable type.
How can I fix this?
Thank you very much
zoogara
(Daryl)
April 26, 2022, 3:45am
8
If you paste just the template in the template editor, what is returned?
Assuming it’s fine, try removing the double quotes around the templated value.
Also - if you use from 0-100 as your value, your light will never get to full brightness.
ixica9790
(Charly Andrey)
April 26, 2022, 9:40am
9
I’ve put it in the template editor and it worked, the value of the pot is displayed! Already a victory for me!
But I still get the same error as before:
Message malformed: expected float for dictionary value @ data['brightness_pct]
I think I have to convert the variable type form string to float. But I don’t know how to do that.
Thank you very much!
zoogara
(Daryl)
April 27, 2022, 7:20am
10
Did you get this working? If not post the whole automation for controlling the light, not just snippets.
ixica9790
(Charly Andrey)
April 27, 2022, 10:51am
11
No I didn’t. I still get errors.
Here is my script:
alias: Brightness using pot
sequence:
- type: turn_on
device_id: 91bf21e23839e3659d64534b63611eec
entity_id: light.cuisine
domain: light
brightness_pct: {{ states('sensor.potentiometre') }}
mode: single
And here is the error I get
Message malformed: expected float for dictionary value @ data['brightness_pct]
zoogara
(Daryl)
April 28, 2022, 4:08am
12
Ah - a script - ok - this is tested and works:
light_adjust_with_pot:
alias: Brightness using pot
sequence:
- variables:
new_brightness: "{{ states('sensor.potentiometre') | float }}"
- service: light.turn_on
data:
device_id: 91bf21e23839e3659d64534b63611eec
entity_id: light.cuisine
domain: light
data_template:
brightness_pct: "{{ new_brightness }}"
mode: single
ixica9790
(Charly Andrey)
April 28, 2022, 5:56am
13
It works! Thank you so much!
I like this forum. Everybody try to help and I think this is beautiful.
If I was living near of you I would pay you a drink.
Thanks again for help