Adding sensor value to input number helper

I’m new to using helpers in Home Assistant, so I’m probably doing something wrong here. I’m trying to have a helper store the total lifetime solar production into a helper.

The traces show that it finishes the math of adding both numbers properly as the value, so I know the value section is correct. The automation completes with no error, but it never updates the helper value.

  alias: Lifetime Solar Production
  description: ''
  trigger:
  - platform: time
    at: '23:00:00'
  condition: []
  action:
  - event: ''
    event_data:
      action: input_number.set_value
      metadata: {}
      target:
        entity_id: 'input_number.lifetime_solar_energy'
      data:
        value: "{{ states('input_number.lifetime_solar_energy') | float(0) + states('sensor.envoy_energy_production_today') | float(0) }}"
  mode: single

I know the single quotes on the entity_id line are not standard and I added those in my last iteration, it also did not work without them.

That’s nonsense.

alias: Lifetime Solar Production
description: ''
triggers:
  - trigger: time
    at: '23:00:00'
conditions: []
actions:
  - action: input_number.set_value
    metadata: {}
    target:
      entity_id: input_number.lifetime_solar_energy
    data:
      value: "{{ states('input_number.lifetime_solar_energy') | float(0) + states('sensor.envoy_energy_production_today') | float(0) }}"
mode: single

Unfortunately when I remove that part (I did also try copy/paste to make sure I didn’t mess it up) I get:
Automation is unavailable

Actions: string value is None for dictionary value @ data[0][‘event’]

Edit: To clarify I have been editing the automations.yaml file directly, though the automation started from the GUI.

Are you reloading automations or restarting HA after your edits?

Yes, prior to those edits, the automation would fire and display the completed math in the value output in traces, just failing to update the input number helper. After the edits, the automation no longer loads and shows up in red on the automations list.

It would be a lot simpler to use a Utility Meter helper with no reset cycle. It will just count up your solar energy forever. It does not matter if your daily sensor resets.

2 Likes

Paste your entire configuration.yaml here with any sensitive information (passwords, API keys, public IP addresses) redacted.

The error you are getting is not from the most recent section of config you posted.

My configuration.yaml is very bare-bones. The only thing I’ve changed is the purge_keep_days so I can have a year-long view of panel production.

# Loads default set of integrations. Do not remove.
default_config:

# Load frontend themes from the themes folder
frontend:
  themes: !include_dir_merge_named themes


script: !include scripts.yaml
scene: !include scenes.yaml
automation: !include automations.yaml

recorder:
  purge_keep_days: 365

I was hoping someone might have a simpler solution, I didn’t notice that option when creating the helper.
I do still want to fix the issue here since it seems it might be wider than just this helper.

That is not recommended. It can lead to performance issues. Please don’t set it to longer than 30 days.

Use long term statistics instead. They are kept forever.

That sounds great. I searched around and found that the long term statistics table saves states every hour and lasts indefinitely, but no reference as to where that is kept or how to reference it.

I have statistics graphs showing the data that I want to keep and have worked for the past 3 months; how do I know if they are pulling from the short term statistics or long term statistics tables? I’d like to revert the change to my recorder length, but I don’t want to suddenly lose data if I’m referencing short term statistics.

chart_type: line
period: day
type: statistics-graph
entities:
  - [list of device serial numbers]
stat_types:
  - mean
hide_legend: true
days_to_show: 365
title: Annual Panel Performance

It is kept in the recorder database and can be accessed using Home Assistant graph cards or the History panel.

There is no “short term statistics”.

Long term statistics stores 5 minute and hourly data. After your purge_keep_days interval the 5 minute data is purged.

The hourly data is never purged.