My knowledge is limited, so please be kind 
I built a 230V dimmer (PWM controlled) for a heater.
My plan is to dim the power according to unused solar energy.
I use ESPhome for the interface.
It works fine when I use the standard “light card” and change the power manually.
But I want to use a calculated variable (in this case a counter) to adjust the power.
How can I use this variable to adjust the PWM duty signal automatically ?
I read the LEDC manual thousand times but have no idea.
Does it have to be done in HA or ESPhome ?
Is there a way in automations ?
1 Like
Both are possible.
If you can control it with the brightness slider of a light card, then you can control it with an automation or template number entity.
A basic counter-based automation would be something like:
trigger:
- platform: state
entity_id: counter.water_heater
to: null
condition: []
action:
- service: light.turn_on
target:
entity_id: light.water_heater
data:
brightness: "{{ trigger.to_state.state | int(0) }}"
This example would change the brightness setting to the value the counter is set to every time it is changed.
You may want to share your ESPHome config so we can actually see how it works with HA.
Thanks
when I change the counter, nothing happens at the light card

is there a link missing between the counter and the percentage of brightness ?
Does the light.turn_on
service work with this entity using the Developer Tools > Services tool using a non-template value for brightness
?