Automation: store numbers i an new entity

Hi,

i receive every 10 minutes a count of impulses from my electric meter, each impulse is equal to 0.002 kW/h.
I created a imput_number.test, now i want to add every new count to imput_number.test.

I tried this:

alias: Test
trigger:

  • entity_id: sensor.lichtsensor
    platform: state
    action:
    data_template:
    value_template: ‘{{ (states.input.number.test) + (states.sensor.lichtsensor) }}’

but it dont worked for me. Anyone has an idea how to realize to add the ammount of impulses on update to the new entity?

I do something similar to store calculate my daily water usage and the cumulative rain total for a day and to calculate the highest wind gust of the day. all of which i accomplish by pushing the numbers I need to a new MQTT sensor via an automation that publishes the values to a specific topic matching the sensor I created.

Here is the wind gust automations which I just set up recently.

- action:
  - data:
      payload_template: '{{ states(''sensor.ambient_wind_gust'') }}'
      retain: 'true'
      topic: ambient/wind_gust_high
    service: mqtt.publish
  alias: Post Midnight Wind Gust - Reset Gust high
  condition: []
  id: '547457355575862734'
  trigger:
  - at: 00:00:01
    platform: time
- id: '1548084513462'
  alias: Update Wind Gust High
  trigger:
  - platform: template
    value_template: '{{ states(''sensor.ambient_wind_gust'') | int > states(''sensor.wind_gust_high'') | int }}'
  action:
  - data:
      payload_template: '{{ states(''sensor.ambient_wind_gust'') }}'
      retain: 'true'
      topic: ambient/wind_gust_high
    service: mqtt.publish

and the mqtt sensor:

sensor:
  - platform: mqtt
    state_topic: "ambient/wind_gust_high"
    name: "Wind Gust High"
    unit_of_measurement: "mph"
    icon: mdi:weather-windy-variant

I redesigned my sensors

# Satelite ONE Impulse Counter
  - platform: mqtt
    state_topic: '/satellite_one/Strom/Count'
    name: "StromImpuls"
    unit_of_measurement: 'Count'
    qos: 0

This sensor reporting every minute the amount of impulses from my electric meter. (500 Impulses = 1 Kilowatt Hour)

In my old homeautomation (iobroker) i add on every update the count of impulses to a variable EnergyTemp, an write the total amount at 23:59 to a new variable called DailyAmmount and reset the EnergyTemp.
So i got a historical daily energy graph.

Im trying to understand your idea. You create a non existant mqtt sensor an feed this with data? And which of your sensor generate the real data?

i got something semi working

- id: '1548508784794'
  alias: MQTT Trigger1
  trigger:
  - platform: mqtt
    topic: /satellite_one/Strom/Count
  action:
    service: input_number.set_value
    data_template:
      entity_id: input_number.test1
      value: "{{ trigger.payload }}"

On Update the input_number.test1 is filled with the count from the mqtt topic.
The question now is, how i can count it, some thing like {{ input_number.test1 + trigger.payload}}

yes sorry you’ll need a value template to add the new count to the existing one.

I use subtraction to get my daily water meter, it uses a template sensor and a value template to compute the sensor amount.

- platform: template
  sensors:
    water:
      value_template: '{%- if not (is_state("sensor.water_meter","unknown") or is_state("sensor.water_prior_day","unknown") )-%}  {{ (((states.sensor.water_meter.state | float) - (states.sensor.water_prior_day.state | float))) | max (0) | round(2) }} {%- endif -%}'
      friendly_name: "Water Today CF"
      unit_of_measurement: "CF"

Sow in this example the sensor.water_meter is the incoming water meter reading. the sensor.water_prior_day is the value pushed from mqtt to the made up mqtt sensor to save the prior day’s total. The checks at the beginning just make sure the data is all there and not unkown to do the calculation.

I would assume you can do something similar but with adding instead of subtracting.