How to adjust dim level based on power injection/power consumption

My setup:
I have a Belgian digital meter which measures power consumption/injection. I also have an electric boiler to store energy from our solar panels. The idea is very much the same as this topic where I drew almost all of the inspiration from. I also have an ESP32 connected with DMX to the phase cut dimmer which drives the electric boiler. With the esphome integration, I can now dim the boiler, so far so good.

My problem
I want to drive the dimmer (0-100) according to the power injection. The boiler is 2400W and the dimmer has steps from 1-100. So my idea would be that once an automation sees there is 48W of power injection to increase the power of the dimmer with 2% ( 2 * 2400 / 100). If it sees 480W of power injection, increase the dimmer with 20% (and so on). Also the other way around, if it sees 960W of power consumption, decrease the power of the dimmer with 40%.

Doing so I would ideally end up with neglegible power injection as long as the boiler needs to heat.

The furthest I got is the code snippet below from automations.yml. If it sees 0.1kW (100W) power injected, it will increase the dimmer level (but by how much?). The opposite (decrease dimmer) if it sees power consumption.

I think my example will be a bit crude and lag behind if power fluctuates heavily (cloudy days, or suddenly a power increase of 1000W or so).

Also, how do I stop the automation from constantly triggering if the dimmer is set to 0 or 100? If it’s at 100% and there is eg. 400W power injection, it doesn’t need to try to add even more % to the dimmer, because it’s already at 100%.

I have read a bit about variables but I 'm no certain, that’s the way to go.

- id: '1668714612055'
  alias: Elektric boiler more power
  description: ''
  trigger:
  - platform: numeric_state
    entity_id: sensor.electricity_meter_power_production
    above: 0.1
  condition: []
  action:
  - device_id: 33d0b65673baf0516eb7eba4a1f503fb
    domain: light
    entity_id: light.boiler_dmx_controller_dimmer
    type: brightness_increase
  mode: single
- id: '1668714879518'
  alias: Eletrische boiler less power
  description: ''
  trigger:
  - platform: numeric_state
    entity_id: sensor.electricity_meter_power_consumption
    above: 0.1
  condition: []
  action:
  - device_id: 33d0b65673baf0516eb7eba4a1f503fb
    domain: light
    entity_id: light.boiler_dmx_controller_dimmer
    type: brightness_decrease
  mode: single

Hi there! Glad you like my little write-up. It really makes me happy to see a couple of people doing this too :smiley:

First of all - 2400W might be pushing it, if you use the same dimmer I do - it’s rated for max 10A and 2300W - I set max_power: 0.75 to avoid overloading the dimmer

secondly, do you EXCLUSIVELY want to heat the boiler with solar power, or do you also want to be able to heat it when there’s no solar production (with the dimmer)?

If you only want to use the dimmer for excess solar power it should be quite straight forward. You can put a template in the action, which calculates something like this:

action:
  - service: light.turn_on
    target:
      entity_id: light.boiler_dmx_controller_dimmer
    data:
      brightness_step_pct: #< here should be the template which calculates the desired percentage step

then it doesn’t matter if it tries to go over 100% - it just can’t

I really can’t help you with templates - I struggle with them every time I try…

Also (and for this reason) I tend to use NodeRed for stuff like that. Making a flow can be as simple as this:

you just read the total power consumption/production and according to the current value, you increase or decrease the dimmer (don’t forget that there has to be some room where there is no action - in this case between 100W production and 100W consumption - this is probably quite much … in my case it’s between 1W production and 40W consumption)

and here the code for the flow:

[{"id":"b53599d6493b9525","type":"switch","z":"6f76ee22d6c5c8da","name":"","property":"payload","propertyType":"msg","rules":[{"t":"gte","v":"1","vt":"num"},{"t":"gte","v":"0.5","vt":"num"},{"t":"gte","v":"0.1","vt":"num"},{"t":"else"}],"checkall":"false","repair":false,"outputs":4,"x":2450,"y":1760,"wires":[["f41fbe7b9c2632d2"],["86555397bbe156d0"],["8d859efe7be9b5ac"],[]]},{"id":"8d859efe7be9b5ac","type":"api-call-service","z":"6f76ee22d6c5c8da","name":"Dimmer +1%","server":"938bbb0d.d39038","version":5,"debugenabled":false,"domain":"light","service":"turn_on","areaId":[],"deviceId":[],"entityId":["light.boiler_steuerung_dimmer"],"data":"{\"brightness_step_pct\": \"+1\"}","dataType":"json","mergeContext":"","mustacheAltTags":false,"outputProperties":[],"queue":"none","x":2730,"y":1760,"wires":[[]]},{"id":"86555397bbe156d0","type":"api-call-service","z":"6f76ee22d6c5c8da","name":"Dimmer +3%","server":"938bbb0d.d39038","version":5,"debugenabled":false,"domain":"light","service":"turn_on","areaId":[],"deviceId":[],"entityId":["light.boiler_steuerung_dimmer"],"data":"{\"brightness_step_pct\": \"+3\"}","dataType":"json","mergeContext":"","mustacheAltTags":false,"outputProperties":[],"queue":"none","x":2730,"y":1720,"wires":[[]]},{"id":"f41fbe7b9c2632d2","type":"api-call-service","z":"6f76ee22d6c5c8da","name":"Dimmer +5%","server":"938bbb0d.d39038","version":5,"debugenabled":false,"domain":"light","service":"turn_on","areaId":[],"deviceId":[],"entityId":["light.boiler_steuerung_dimmer"],"data":"{\"brightness_step_pct\": \"+5\"}","dataType":"json","mergeContext":"","mustacheAltTags":false,"outputProperties":[],"queue":"none","x":2730,"y":1680,"wires":[[]]},{"id":"73da8cdb2124d33d","type":"api-call-service","z":"6f76ee22d6c5c8da","name":"Dimmer -1%","server":"938bbb0d.d39038","version":5,"debugenabled":false,"domain":"light","service":"turn_on","areaId":[],"deviceId":[],"entityId":["light.boiler_steuerung_dimmer"],"data":"{\"brightness_step_pct\": \"-1\"}","dataType":"json","mergeContext":"","mustacheAltTags":false,"outputProperties":[],"queue":"none","x":2730,"y":1940,"wires":[[]]},{"id":"44c8d269d63fa3e6","type":"api-call-service","z":"6f76ee22d6c5c8da","name":"Dimmer -5%","server":"938bbb0d.d39038","version":5,"debugenabled":false,"domain":"light","service":"turn_on","areaId":[],"deviceId":[],"entityId":["light.boiler_steuerung_dimmer"],"data":"{\"brightness_step_pct\": \"-5\"}","dataType":"json","mergeContext":"","mustacheAltTags":false,"outputProperties":[],"queue":"none","x":2730,"y":1900,"wires":[[]]},{"id":"0fb694bd4aae77c4","type":"api-call-service","z":"6f76ee22d6c5c8da","name":"Dimmer -20%","server":"938bbb0d.d39038","version":5,"debugenabled":false,"domain":"light","service":"turn_on","areaId":[],"deviceId":[],"entityId":["light.boiler_steuerung_dimmer"],"data":"{\"brightness_step_pct\": \"-20\"}","dataType":"json","mergeContext":"","mustacheAltTags":false,"outputProperties":[],"queue":"none","x":2740,"y":1860,"wires":[[]]},{"id":"fe03067358457ed6","type":"api-call-service","z":"6f76ee22d6c5c8da","name":"Dimmer -50%","server":"938bbb0d.d39038","version":5,"debugenabled":false,"domain":"light","service":"turn_on","areaId":[],"deviceId":[],"entityId":["light.boiler_steuerung_dimmer"],"data":"{\"brightness_step_pct\": \"-50\"}","dataType":"json","mergeContext":"","mustacheAltTags":false,"outputProperties":[],"queue":"none","x":2740,"y":1820,"wires":[[]]},{"id":"71e607aa41ee4b72","type":"switch","z":"6f76ee22d6c5c8da","name":"","property":"payload","propertyType":"msg","rules":[{"t":"gte","v":"1","vt":"num"},{"t":"gte","v":"0.5","vt":"num"},{"t":"gte","v":"0.2","vt":"num"},{"t":"gte","v":"0.1","vt":"num"},{"t":"else"}],"checkall":"false","repair":false,"outputs":5,"x":2450,"y":1840,"wires":[["fe03067358457ed6"],["0fb694bd4aae77c4"],["44c8d269d63fa3e6"],["73da8cdb2124d33d"],[]]},{"id":"9864cbc0f8805de2","type":"server-state-changed","z":"6f76ee22d6c5c8da","name":"sensor.electricity_meter_power_production","server":"938bbb0d.d39038","version":4,"exposeToHomeAssistant":false,"haConfig":[{"property":"name","value":""},{"property":"icon","value":""}],"entityidfilter":"sensor.shelly_3em_total_power","entityidfiltertype":"exact","outputinitially":false,"state_type":"str","haltifstate":"","halt_if_type":"num","halt_if_compare":"is","outputs":1,"output_only_on_state_change":false,"for":"0","forType":"num","forUnits":"minutes","ignorePrevStateNull":false,"ignorePrevStateUnknown":false,"ignorePrevStateUnavailable":false,"ignoreCurrentStateUnknown":false,"ignoreCurrentStateUnavailable":false,"outputProperties":[{"property":"payload","propertyType":"msg","value":"","valueType":"entityState"},{"property":"data","propertyType":"msg","value":"","valueType":"eventData"},{"property":"topic","propertyType":"msg","value":"","valueType":"triggerId"}],"x":2120,"y":1780,"wires":[["b53599d6493b9525"]]},{"id":"cc56f8235bf015ab","type":"server-state-changed","z":"6f76ee22d6c5c8da","name":"sensor.electricity_meter_power_consumption","server":"938bbb0d.d39038","version":4,"exposeToHomeAssistant":false,"haConfig":[{"property":"name","value":""},{"property":"icon","value":""}],"entityidfilter":"sensor.shelly_3em_total_power","entityidfiltertype":"exact","outputinitially":false,"state_type":"str","haltifstate":"","halt_if_type":"num","halt_if_compare":"is","outputs":1,"output_only_on_state_change":false,"for":"0","forType":"num","forUnits":"minutes","ignorePrevStateNull":false,"ignorePrevStateUnknown":false,"ignorePrevStateUnavailable":false,"ignoreCurrentStateUnknown":false,"ignoreCurrentStateUnavailable":false,"outputProperties":[{"property":"payload","propertyType":"msg","value":"","valueType":"entityState"},{"property":"data","propertyType":"msg","value":"","valueType":"eventData"},{"property":"topic","propertyType":"msg","value":"","valueType":"triggerId"}],"x":2110,"y":1820,"wires":[["71e607aa41ee4b72"]]},{"id":"938bbb0d.d39038","type":"server","name":"Home Assistant","version":5,"addon":true,"rejectUnauthorizedCerts":true,"ha_boolean":"y|yes|true|on|home|open","connectionDelay":true,"cacheJson":true,"heartbeat":false,"heartbeatInterval":30,"areaSelector":"friendlyName","deviceSelector":"friendlyName","entitySelector":"friendlyName","statusSeparator":"at: ","statusYear":"hidden","statusMonth":"short","statusDay":"numeric","statusHourCycle":"h23","statusTimeFormat":"h:m","enableGlobalContextStore":true}]

I don’t think this actually matters, but if you go the Automations way, you could simply set a condition which says not to continue if the dimmer is at 0 (when lowering) or 100 (when raising)

Another thing to consider: do you actually get live data from the meter? I don’t have a smart meter, but I’ve heard that they only send data every 5 or 15 minutes … which would be completely useless for that use case.

it will :wink: I went up to 99,5% self-consumption every day (from under 50% before, on sunny days)

@Farnsworth: I get to talk to the Grand Master himself :smiley: . I think I took an almost exact copy of your setup :slight_smile: except for the boiler indeed. I have already topped of the maximum dimming level. I thought it was rated at 2400W but I checked on the dimmer itself and it says 2300W so I need to lower the maximum level a bit.

With regards to the node-red code … confession of the week: I don’t understand at all how it works and how I should integrate it in Home Assistant, that’s why I was trying to find my own solution. I reckon integrating the node red generated code is just copy paste in the configuration.yaml file. But then? How do I continue? It likely needs to know the entity of my power production and the dimmer itself?

Yes I want to run it ~exclusively on solar power. The dimmer itself comes with a slider and an integrated slider. The highest value takes precedence. If DMX sends a signal to go for 0% (at night) and you slide it up to 75%, it will dim at 75%. If you dim the slider to 25% and DMX says 80%, it will dim at 80%. Doing so, if there’s not enough hot water and no sun to wait for, I can always temporarily slide it up (and set an alarm to slide it back down :wink: )

far from it … more like: even a broken clock is right twice a day :joy:

Ok, I’m trying my best to explain

Installing NodeRed is super simple and straight forward: just go to your settings - Add-ons - Add-on Store and install Node Red. I believe that’s all there is to it. (I have a credential_secret set in the configuration but not sure if that’s even necessary)
Now start it and enable “start on boot” (and add it to the side-panel for quick access)

When it’s started, go to the web interface (there’ll probably be some welcome/tutorial messages to give you a quick overview), click on the menu icon in te top right corner - import - paste the code I posted, click import and then just place the flow somewhere.

Now that that’s done, you’ll have to make some changes to it, to fit your configuration.

doubleclick in the sensor.electricity_meter_power_production (that’s just the name I gave it and doesn’t mean anything) node and select your actual sensor.electricity_meter_power_production in the Entity field.
do the same thing for sensor.electricity_meter_power_consumption Node.

now change the Dimmer % Nodes: first set the right device as Entity for each one of them (your dimmer).

Next you want to change the percentage steps. To do that, we need to look at the whole flow:

The sensor.electricity_meter_power_production and sensor.electricity_meter_power_consumption nodes only report power values (important question - what do they report? W or kW, and what’s the resolution? - for now I’ll assume it’s kW and a resolution of 0.1kW). Now the switch Node see this value and according to the settings, route it through one of the exits.
So, the smartmeter reports there’s 1.3kW production - the switch sees this and determines 1.3kW is more than 1 so it gets routet through the first exit - and the first exit goes to the Dimmer +5% node, so the dimmer adds 5%
as you can see, there’s an “exit” saying “ansonsten” (=else) - so if none of the above apply, nothing will happen, because nothing is connected to this exit.

I believe it’s better to change the percentage in steps instead of setting definite vales - it makes the flow more versatile and simple. Otherwise you’d have to add a lot more Dimmer states to achive the same “resolution”.

Ok, back to the flow. Well, I believe it’s actually done now. Don’t forget to deploy your changes (big red button in the top right) … all you have to do now is to observe a litte what values in the switch node and what percentage steps make the most sense.

ok, I took the liberty to refine the flow a bit - you should be able to just import it and only change the entities as described above :wink:

it is configured to start the dimmer as soon as there’s more than 0.1kW excess power and stop it as soon as there’s power draw from mains.

you should observe it a little and see if it behaves the way you want it to - and then change the thresholds of the switch and percentage steps to refine it even more :wink:

[{"id":"91c85c02cdecad80","type":"switch","z":"37d6892f50d80d96","name":"","property":"payload","propertyType":"msg","rules":[{"t":"gte","v":"2.5","vt":"num"},{"t":"eq","v":"1.5","vt":"str"},{"t":"gte","v":"0.5","vt":"num"},{"t":"eq","v":"0.2","vt":"str"},{"t":"gte","v":"0.1","vt":"num"},{"t":"else"}],"checkall":"false","repair":false,"outputs":6,"x":1110,"y":1120,"wires":[["ce00faeb54982ab8"],["21de4e72b8ae40d3"],["3740f6e6b8ac9ba0"],["c070fbed4485437c"],["a551c7a4250f53ee"],[]]},{"id":"a551c7a4250f53ee","type":"api-call-service","z":"37d6892f50d80d96","name":"Dimmer +1%","server":"938bbb0d.d39038","version":5,"debugenabled":false,"domain":"light","service":"turn_on","areaId":[],"deviceId":[],"entityId":["light.boiler_steuerung_dimmer"],"data":"{\"brightness_step_pct\": \"+1\"}","dataType":"json","mergeContext":"","mustacheAltTags":false,"outputProperties":[],"queue":"none","x":1390,"y":1140,"wires":[[]]},{"id":"3740f6e6b8ac9ba0","type":"api-call-service","z":"37d6892f50d80d96","name":"Dimmer +25%","server":"938bbb0d.d39038","version":5,"debugenabled":false,"domain":"light","service":"turn_on","areaId":[],"deviceId":[],"entityId":["light.boiler_steuerung_dimmer"],"data":"{\"brightness_step_pct\": \"+25\"}","dataType":"json","mergeContext":"","mustacheAltTags":false,"outputProperties":[],"queue":"none","x":1400,"y":1060,"wires":[[]]},{"id":"ce00faeb54982ab8","type":"api-call-service","z":"37d6892f50d80d96","name":"Dimmer +100%","server":"938bbb0d.d39038","version":5,"debugenabled":false,"domain":"light","service":"turn_on","areaId":[],"deviceId":[],"entityId":["light.boiler_steuerung_dimmer"],"data":"{\"brightness_step_pct\": \"+100\"}","dataType":"json","mergeContext":"","mustacheAltTags":false,"outputProperties":[],"queue":"none","x":1400,"y":980,"wires":[[]]},{"id":"9c1d25c75bc0b00d","type":"api-call-service","z":"37d6892f50d80d96","name":"Dimmer -1%","server":"938bbb0d.d39038","version":5,"debugenabled":false,"domain":"light","service":"turn_on","areaId":[],"deviceId":[],"entityId":["light.boiler_steuerung_dimmer"],"data":"{\"brightness_step_pct\": \"-1\"}","dataType":"json","mergeContext":"","mustacheAltTags":false,"outputProperties":[],"queue":"none","x":1390,"y":1360,"wires":[[]]},{"id":"a86f3c56f89b23b6","type":"api-call-service","z":"37d6892f50d80d96","name":"Dimmer -3%","server":"938bbb0d.d39038","version":5,"debugenabled":false,"domain":"light","service":"turn_on","areaId":[],"deviceId":[],"entityId":["light.boiler_steuerung_dimmer"],"data":"{\"brightness_step_pct\": \"-3\"}","dataType":"json","mergeContext":"","mustacheAltTags":false,"outputProperties":[],"queue":"none","x":1390,"y":1320,"wires":[[]]},{"id":"e658143d241adbcf","type":"api-call-service","z":"37d6892f50d80d96","name":"Dimmer -25%","server":"938bbb0d.d39038","version":5,"debugenabled":false,"domain":"light","service":"turn_on","areaId":[],"deviceId":[],"entityId":["light.boiler_steuerung_dimmer"],"data":"{\"brightness_step_pct\": \"-25\"}","dataType":"json","mergeContext":"","mustacheAltTags":false,"outputProperties":[],"queue":"none","x":1400,"y":1280,"wires":[[]]},{"id":"f46ca99da1feb9ae","type":"api-call-service","z":"37d6892f50d80d96","name":"Dimmer -50%","server":"938bbb0d.d39038","version":5,"debugenabled":false,"domain":"light","service":"turn_on","areaId":[],"deviceId":[],"entityId":["light.boiler_steuerung_dimmer"],"data":"{\"brightness_step_pct\": \"-50\"}","dataType":"json","mergeContext":"","mustacheAltTags":false,"outputProperties":[],"queue":"none","x":1400,"y":1240,"wires":[[]]},{"id":"2a46f031e12ed2c2","type":"switch","z":"37d6892f50d80d96","name":"","property":"payload","propertyType":"msg","rules":[{"t":"gte","v":"2","vt":"str"},{"t":"gte","v":"1","vt":"num"},{"t":"gte","v":"0.5","vt":"num"},{"t":"gte","v":"0.2","vt":"num"},{"t":"gte","v":"0","vt":"num"},{"t":"else"}],"checkall":"false","repair":false,"outputs":6,"x":1110,"y":1220,"wires":[["f7d62ae02292de92"],["f46ca99da1feb9ae"],["e658143d241adbcf"],["a86f3c56f89b23b6"],["9c1d25c75bc0b00d"],[]]},{"id":"974f9dbf97ce08c0","type":"server-state-changed","z":"37d6892f50d80d96","name":"sensor.electricity_meter_power_production","server":"938bbb0d.d39038","version":4,"exposeToHomeAssistant":false,"haConfig":[{"property":"name","value":""},{"property":"icon","value":""}],"entityidfilter":"sensor.shelly_3em_total_power","entityidfiltertype":"exact","outputinitially":false,"state_type":"str","haltifstate":"","halt_if_type":"num","halt_if_compare":"is","outputs":1,"output_only_on_state_change":false,"for":"0","forType":"num","forUnits":"minutes","ignorePrevStateNull":false,"ignorePrevStateUnknown":false,"ignorePrevStateUnavailable":false,"ignoreCurrentStateUnknown":false,"ignoreCurrentStateUnavailable":false,"outputProperties":[{"property":"payload","propertyType":"msg","value":"","valueType":"entityState"},{"property":"data","propertyType":"msg","value":"","valueType":"eventData"},{"property":"topic","propertyType":"msg","value":"","valueType":"triggerId"}],"x":780,"y":1160,"wires":[["91c85c02cdecad80"]]},{"id":"7a6e1780f91a6535","type":"server-state-changed","z":"37d6892f50d80d96","name":"sensor.electricity_meter_power_consumption","server":"938bbb0d.d39038","version":4,"exposeToHomeAssistant":false,"haConfig":[{"property":"name","value":""},{"property":"icon","value":""}],"entityidfilter":"sensor.shelly_3em_total_power","entityidfiltertype":"exact","outputinitially":false,"state_type":"str","haltifstate":"","halt_if_type":"num","halt_if_compare":"is","outputs":1,"output_only_on_state_change":false,"for":"0","forType":"num","forUnits":"minutes","ignorePrevStateNull":false,"ignorePrevStateUnknown":false,"ignorePrevStateUnavailable":false,"ignoreCurrentStateUnknown":false,"ignoreCurrentStateUnavailable":false,"outputProperties":[{"property":"payload","propertyType":"msg","value":"","valueType":"entityState"},{"property":"data","propertyType":"msg","value":"","valueType":"eventData"},{"property":"topic","propertyType":"msg","value":"","valueType":"triggerId"}],"x":770,"y":1200,"wires":[["2a46f031e12ed2c2"]]},{"id":"c070fbed4485437c","type":"api-call-service","z":"37d6892f50d80d96","name":"Dimmer +3%","server":"938bbb0d.d39038","version":5,"debugenabled":false,"domain":"light","service":"turn_on","areaId":[],"deviceId":[],"entityId":["light.boiler_steuerung_dimmer"],"data":"{\"brightness_step_pct\": \"+3\"}","dataType":"json","mergeContext":"","mustacheAltTags":false,"outputProperties":[],"queue":"none","x":1390,"y":1100,"wires":[[]]},{"id":"21de4e72b8ae40d3","type":"api-call-service","z":"37d6892f50d80d96","name":"Dimmer +50%","server":"938bbb0d.d39038","version":5,"debugenabled":false,"domain":"light","service":"turn_on","areaId":[],"deviceId":[],"entityId":["light.boiler_steuerung_dimmer"],"data":"{\"brightness_step_pct\": \"+50\"}","dataType":"json","mergeContext":"","mustacheAltTags":false,"outputProperties":[],"queue":"none","x":1400,"y":1020,"wires":[[]]},{"id":"f7d62ae02292de92","type":"api-call-service","z":"37d6892f50d80d96","name":"Dimmer -100%","server":"938bbb0d.d39038","version":5,"debugenabled":false,"domain":"light","service":"turn_on","areaId":[],"deviceId":[],"entityId":["light.boiler_steuerung_dimmer"],"data":"{\"brightness_step_pct\": \"-75\"}","dataType":"json","mergeContext":"","mustacheAltTags":false,"outputProperties":[],"queue":"none","x":1400,"y":1200,"wires":[[]]},{"id":"938bbb0d.d39038","type":"server","name":"Home Assistant","version":5,"addon":true,"rejectUnauthorizedCerts":true,"ha_boolean":"y|yes|true|on|home|open","connectionDelay":true,"cacheJson":true,"heartbeat":false,"heartbeatInterval":30,"areaSelector":"friendlyName","deviceSelector":"friendlyName","entitySelector":"friendlyName","statusSeparator":"at: ","statusYear":"hidden","statusMonth":"short","statusDay":"numeric","statusHourCycle":"h23","statusTimeFormat":"h:m","enableGlobalContextStore":true}]

@Farnsworth: Love the analogy of the clock! :rofl: I need to remember that one!

And you’re too kind taking so much time explaining, but I guess I understand now how it’ll fit in. I’ll try this evening to install Node Red on my RPI. I have it running in a venv but I think I found a manual to install it from the command line.

Thanks also for refining the code! I’d like to start from 0.024kW, I’ll see if I can make it work.

Either way, I’ve got a much better feeling about it now, I guess, I’ll be able to figure it out this evening!

OK I think I have a working code. I’ll see tomorrow how accurate it is. I have made extra “contacts” to each switch. Increments of 1 from 1%-10% and increments of 5% from 10%-100%. I don’t know what this will give. I mainly did this since the DSMR integration seems to update the consumption/production only once every 30 seconds so I want this “automation” to be as close as possible from the first attempt.

I’m working to update the power production/consumption to update every second with a separate command_line command, but for the life of me, I can’t make it work.

--- I took out the code, since it was not working as expected ---