Hi there, I’m fairly new with homeassistant and tried to build my own sensors to simulate a battery. Basically I want to have data on how much energy from my solar panels I could use if I had a 1.92 kWh battery. Therefore, I installed a shelly Pro 3EM. I generated a inverted sensor, so it shows me the power that would actually charge the battery. Further, I generated the follwoing sensors in the templates.yaml:
- trigger:
- platform: time_pattern
seconds: "/30"
- platform: state
entity_id:
- sensor.shellypro3em_power
sensor:
- name: "Shelly Power invertiert"
unique_id: shelly_power_inverted
unit_of_measurement: "W"
device_class: power
state_class: measurement
state: >
{{ (states('sensor.shellypro3em_power') | float(0)) * -1 }}
- trigger:
- platform: time_pattern
seconds: "/10"
- platform: state
entity_id:
- sensor.shelly_power_invertiert
- sensor.battery
sensor:
- name: "effektiv_power"
unit_of_measurement: "W"
state: >
{% set p = states('sensor.shelly_power_invertiert') | float() %}
{% set b = states('sensor.battery') | float(0) %}
{% if b <= 0 %}
{{ [p, 0] | max }}
{% elif b >= 1.92 %}
{{ [p, 0] | min }}
{% else %}
{{ p }}
{% endif %}
- name: "power safed"
unit_of_measurement: "W"
state: >
{% set p = states('sensor.shelly_power_invertiert') | float() %}
{% set b = states('sensor.battery') | float(0) %}
{% if b < 1.92 %}
{{ [p, 0] | max }}
{% elif b >= 1.92 %}
0
{% endif %}
- name: "power over battery"
unit_of_measurement: "W"
state: >
{% set p = states('sensor.shelly_power_invertiert') | float() %}
{% set b = states('sensor.battery') | float(0) %}
{% if b >= 1.92 %}
{{ [p, 0] | max }}
{% else %}
0
{% endif %}
In my configuration.yaml I have following integration sensors:
sensor:
- platform: integration
name: Battery
source: sensor.effektiv_power
unit_prefix: k
round: 3
max_sub_interval:
seconds: 30
- platform: integration
name: "additional power"
source: sensor.power_safed
unit_prefix: k
round: 3
max_sub_interval:
seconds: 30
- platform: integration
name: "lost power"
source: sensor.power_over_battery
unit_prefix: k
round: 3
max_sub_interval:
seconds: 30
So far so good. I figgured, that the sensor.shelly_power_invertiert updated as I desired. Meaning, when I gave it a time_pattern trigger only, it triggerd accordint to this time patter, if it had a entity_id-trigger, it used that. When I wanted to do the same for the other sensors, they do not get a update if they stay at the same value.
Usually, that wouldn’t really be a problem, however, since I want to integrate the power that was saved in my battery, it seems that the integration doesn’t do what I want it. Basically, when the last change was at 17:00 and the next update comes at 10:00, the integration sensor extrapolates and assumes, that during this time there was power produced. This then leads to the problem, that, especially if the first reading is high, my Battery assumes it is full instantly. To avoid this, I though I could somehow force the sensors to update, but unitl now, I couldn’t really find a workaround.
I’d be very thankful for your help!

