Solar values don't trigger automations

Dear all,
I’m running a campground in Germany and am currently trying to automate certain chores and processes related to energy and my solar installation. I’m new to HA and managed to get quite some things done. I’m not into fancy dashboards and stuff, but rather into automating things and make my campground smart. That worked like a charm when it came to lighting, motionsensors, surveillance with ring cams and so forth. However I’m struggling with the energy automations.

This is the solar installation I’m running on my campground:

I marked the value which I’m capable of reading out of the smart manager via Modbus sensors. This is the code I’ve used to setup the sensors in HA:

modbus:
  - name: "KSEM"
    type: tcp
    host: 192.168.1.207
    port: 502

    sensors:
    - name: netzbezug_leistung_ksem
      slave: 1
      device_class: power
      state_class: measurement
      unit_of_measurement: W
      scale: 0.1
      address: 0
      scan_interval: 10 # Defines the update interval of the sensor in seconds.
      count: 2 # Anzahl zu lesenden Register
      input_type: holding
      data_type: uint32

    - name: netzeinspeisung_leistung_ksem
      slave: 1
      device_class: power
      state_class: measurement
      unit_of_measurement: W
      scale: 0.1
      address: 2
      scan_interval: 10 # Defines the update interval of the sensor in seconds.
      count: 2 # Anzahl zu lesenden Register
      input_type: holding
      data_type: uint32

I can display that sensors value in HA and it shows the correct values, like my KSEM smart meter does via the web interface.

However, here comes the trouble. I cannot use this value to trigger automations, that could switch any of my shellies or other smart installations I’ve got.

This ist the code I used to create an automation to start the heat pump of our pool, once 2500 Watts of power to grid has been reached and as a condition I added “current pool temperature below 25°C” from a sensor attached to a shelly:

alias: "Energie: Solar Überschuss >2500 W & Pool <25°C = Wärmepumpe Schwimmbad an"
description: >-
  Wenn die Solaranlage mehr als 2500 W über 2 Minuten liefert und der Pool eine
  Temperatur von unter 25°C hat, wird die Wärmepumpe eingeschaltet.
trigger:
  - platform: numeric_state
    entity_id: sensor.netzeinspeisung_energie_ksem
    for:
      hours: 0
      minutes: 2
      seconds: 0
    above: 2500
condition:
  - type: is_temperature
    condition: device
    device_id: f596d7928a8ab756b6bfab6b256abf08
    entity_id: sensor.vorlauf_schwarz_temperature
    domain: sensor
    below: 25
action:
  - type: turn_on
    device_id: f596d7928a8ab756b6bfab6b256abf08
    entity_id: switch.shellyplus1pm_80646fe47d38_switch_0
    domain: switch
mode: single

No worries, it ain’t the shelly switching the heat pump, of course there’s a relais inbetween, switching the 400V heat pump :wink:

I tested both sensors as a condition as well and HA verifies the above or below value state correctly when testing. I also switched condition and trigger to see if that has any effect (pool temp going below 25°C triggers and condition is solar to grid more than 2500) but to no avail. This automation never ran unless triggered manually.

Other automations work well, so I guess it ain’t a general automation prob.

I’m most thankful for the pros around here to take a look at my code and let me know what else I could check to make this work.

Thanks in advance and

sunny regards from the river Neckar in Germany!

leistung versus energie?

Hi, thanks for your reply. Why energy? The system might have delivered a fair amount of energy during a day, but the current power might still not be enough to run my heat pump without drawing from the grid. E.g. the sun might be clouded, then there won’t be enough power from the solar system to run a heat pump. So it should actually be solar power not produced energy, that triggers the heat pump.

I don’t know if this is the problem, but your sensor definition at the top of your first post is for an entity called sensor.netzeinspeisung_leistung_ksem but your automation trigger is looking at an entity called sensor.netzeinspeisung_energie_ksem.

Does sensor.netzeinspeisung_energie_ksem exist, and what values is it showing?

You say:

…but you are not “using that value to trigger”, you’re using a different sensor.

Yep! Sorry, you’re right! Just changed it. Still won’t work. In my first tries I actually used power, but the automation won’t fire.

That numeric state trigger will only fire when the power level goes from below 2500W to above 2500W and stays there for 2 minutes.

If it’s already above 2500W when you reload the automation, it won’t fire. We can work around that if that’s a problem, but in its current state it won’t trigger from startup until the threshold 2500W level is crossed.

If you still think it should have triggered, have a look at the automation traces to see if it did trigger but was blocked by the temperature condition, or if the action was executed but failed for some reason.

Now I feel embarrassed. It’s actually been the case. I used energy and didn’t recognize it the whole time. Thanks for opening my eyes! Now it works.

1 Like

We call it “fresh eyes” in English. It’s much harder to spot one’s own errors than someone else’s. We’ve all been there :slight_smile: .

1 Like