Automation (excess power over x kwh switch on boiler) not working as expected what is wrong

I am trying to use my P1 meter (DSMR Smart Meter intergration) sensor sensor.electricity_meter_power_production to trigger a switch switch.shelly_blokhut_boiler_switch_0

If I trigger the automation manualy it works but one way or the other it never getst triggerd (i am probably missing something / thinking to simple)

My Automation based on examples here , and part of the Gui.

What do I want to accomplish :
When sensor.electricity_meter_power_production => 2650kW for longer than 2 minutes
Then Enable sensor.shelly_blokhut_boiler_switch_0_power
if sensor.electricity_meter_power_production < 2500
Then Disable sensor.shelly_blokhut_boiler_switch_0_power

I have not build the power of part yet as I am not getting it to turn on.
I also tried : above 2650
But no success

alias: Production above 2650kW  boiler on
description: ""
riggers:
  - trigger: numeric_state
    entity_id:
      - sensor.electricity_meter_power_production
    above: 2.65
    for:
      hours: 0
      minutes: 2
      seconds: 0
actions:
  - type: turn_on
    device_id: 206b40e81dc98eace03b00db0fb4fd9d
    entity_id: 607d2e01b9645d5c1591070ca08880d2
    domain: switch
mode: single

Anyone seeing what I am doing wrong here / missing here ?

You’re missing a “t” from triggers. Try this:

alias: Manage the boiler
triggers:
  - trigger: numeric_state
    entity_id: sensor.electricity_meter_power_production
    above: 2.65
    for: "00:02:00"
    id: "on"
  - trigger: numeric_state
    entity_id: sensor.electricity_meter_power_production
    below: 2.5
    id: "off"
actions:
  - action: switch.turn_{{ trigger.id }}
    target:
      entity_id: switch.shelly_blokhut_boiler_switch_0

Notes:

  • You can’t trigger it manually due to the use of the trigger variable.
  • It won’t do anything until one of the two thresholds is crossed.
1 Like

Thanks, biggest question is how where you able to exactly guess my Switch Identity ?
(it is spot on)

The missing T was an issue me struggling with this forum go get the code right.

And thanks for giving me the code to do the on / off procces :slight_smile:

I just realized that I am measuring the production on my grid connection so as soon as I enable the boiler I introduce a load of 2.5kW resulting in production being lower directly.
With this code I will get a switch on / of (with a delay of 2 minutes) so I need to check if the consumption is getting higher than 0 (as than I will no longer be producing more electricity than I am consuming) and than switch the boiler off.

But thanks will give this a go.
My main question is, what is the correct vallue (or how to check this) of the sensor.electricity_meter_power_production

Is this 2650 or 2.65 or 2.650 or 2,65 or 2,650 just curious how to check this raw vallue.

You included it, which was helpful :slight_smile:

Developer Tools / States. Here’s my house power meter reading 0.3kW:

That’s the “official” state: the one you need to use as a comparison in automations etc.

1 Like

Thank you sir :slight_smile:

For a slight moment I thought there was a “translation” tool for the numeric vallue of the Identity ID not knowing I posted my “plan” with the normal identity ID’s :slight_smile:

Next question (sorry thought I was done here but made a wrong assumption)

I wanted to use sensor.electricity_meter_power_consumption to check whether I start consuming more than producing.
But my P1 meter does not show this, I need to calculate this.

So what I want is if sensor.electricity_meter_power_consumption > than sensor.electricity_meter_power_production power off switch.shelly_blokhut_boiler_switch_0

So I need to do something smart (but I am not a coder) with substracting the power consumption vallue from the production vallue sensor.
If the outcome of that substraction is bigger than 0 I need to switch off the switch.

My guess would be something like :

     value_template: >-
          {% set production = states('sensor.electricity_meter_power_production') | int(0) }
          {% set consumption = states('sensor.electricity_meter_power_consumption') | int(0) }
          {{ consumption > production }}
      for: "00:02:00"
      id: "off"

Is this correct ? (Just stealing from other examples here)

Yes, that should work , although watch the line endings:

{% ... %}

Alternatively you can set up a template binary sensor helper and look for that going on for 2 minutes:

1 Like

This is my final version currently running :
By the way I REALLY do not like Yaml :slight_smile:

alias: Manage the boiler
triggers:
  - trigger: numeric_state
    entity_id: sensor.electricity_meter_power_production
    above: 2.65
    for: "00:02:00"
    id: "on"
  - value_template: >-
      {% set production = states('sensor.electricity_meter_power_production') |
      int(0) %} {% set consumption =
      states('sensor.electricity_meter_power_consumption') | int(0) %} {{
      production <= consumption }}
    for: "00:02:00"
    id: "off"
    trigger: template
actions:
  - action: switch.turn_{{ trigger.id }}
    target:
      entity_id: switch.shelly_blokhut_boiler_switch_0

Double alias?

1 Like

My bad I use another alias in my installation so I copies the same one in you used.

1 Like

Oh, one other thing:

You’re using int (integer) filters on the values to compare, yet it looks like the numbers are small (in kW). You will be better using float:

  - value_template: >-
      {% set production =  states('sensor.electricity_meter_power_production')|float(0) %}
      {% set consumption = states('sensor.electricity_meter_power_consumption')|float(0) %}
      {{ production <= consumption }}

@Troon thanks for pointing this out, but as a non coder I have no idea what the difference is between an integer vs a float.
So need to google that so I learn something from it.

The automation is working fine in current config (with the int) only issue / not happy with is the way currently the load (2,5kW) is being switched on and on quite often on a Shelly relay.
Allthough it is perfectly specked to switch 3,6kW I am not sure if this the setup I want to keep (but this is more a electrical worry than an automation issue).

[10 minutes and 1 google search later]
Floats it is :slight_smile:
Thank you sir ! Automation has been adjusted to your suggestion.

1 Like