Automation for power regulator - help needed

Hi community,

I need help for my automation:

There is a sensor “sensor.power_flow”. A negative value shows the energy that is send in the grid (solar + windpower), a positive value means energy from the grid (in Watts). The value updates every 1-2 seconds.

I have a adjustable dimmer that runs on ESPhome, connected to a dumpload (water heater). I can send positive or negative values to raise or lower the output power. Also I can give it a absolute value.

I want to get a power flow around zero.

This is the entry in my automations.yaml:

- id: '1679219749347'
  alias: Nulleinspeisung
  description: ''
  - platform: state
    entity_id: sensor.power_flow
  - service: esphome.leistungssteller_adjust_power
      offset: >-
        {{ states('sensor.power_flow')|float * -1) + 1000 }}
  - delay:
      seconds: 1
      milliseconds: 0
  mode: single

Its not working, thats why I am posting :slight_smile:

The idea is to adjust the dimmer every time the power flow is changing.

I think the trigger works, but im not 100% sure.

The action should be: negate the power flow value and send a correction value to the dimmer. The adjusting-service on the dimmer works so far.
The +1000 is just for testing, because there is no solar production and no negative power_flow value.

Example: 500W infeed to the grid (power_flow is -500 then) → send +500 to the dimmer.

I think a little delay is neccasary to prevent and endless loop sending data all the time.

The input values differ around 10% from the real output. So I think the system should self iterate a bit, so the deviation should level out.

Not sure where the problem is, probably the syntax. Or the self iteration?

I never figured out how to do calculations in yaml with this C++ stuff mixed in. I do not understand how and where to use it right…
Most in my ESPhome programm is copy and paste and trying endless hours until I got the right syntax…

Any ideas or suggestions here?

Thanks folks,


Check the automation’s trace.

the automations trace is only available if I used the automation input mask, or am I’m wrong?

But I made another test automation via dialog one just with the trigger, and its shows that its triggered on every change of sensor.power_flow

What’s an “automation input mask”?

Sorry, im not a native english speaker, so maybe I use the wrong terms.

I can edit the automations.yaml direct, or use this:

If you use the Automation Editor to create an automation, Home Assistant automatically assigns it an unique_id id option with a random value. That information is stored in a hidden file and used when generating a trace.

If you create an automation manually (i.e. directly edit the automations.yaml file) Home Assistant doesn’t automatically give it an id option. If you want a trace for the manually-created automation, you should add id with a unique value. (That’s how I recall it used to work; maybe it’s different now.)

Anyway, your most recent experiment confirms that the State Trigger is working. Now you need to determine if the service call is working. I am unfamiliar with that esphome service call. I assume it’s a custom service call you created for your dimmer device?


Correction. Don’t know why I said unique_id because it should be id. :man_facepalming:t3:

As you see in the code, there is an id. But its not called uniqe_id.
I started from the editor, but when i changed it in the yaml, it disappeared in the automations in the UI.
For some reason it now came back.

The service is working fine. Tested it in the developer section and it changes the output in real and so it affects the power flow.