#Persistent storage of a value

1 messages · Page 1 of 1 (latest)

stoic vigil
#

Hi!
What is the preferred (and not too complicated) way to persistently store a value to be able to reference it at a later time? SQL? MQTT? other?
I have Mosquitto installed. I would be writing the value when an automation runs and reading it (to check a condition) when the automation runs again.

zinc field
#

Any of the helpers

stoic vigil
#

Sorry, I don't understand. I've looked at helpers (input numbers and template sensors), but that doesn't seem to be what I need.

zinc field
#

They do exactly what you requested

#

Store a value and use it later

stoic vigil
#

Input numbers seem to require maximum and minimum values and template sensors some type of value template. I don't want to set a maximum and I don't know what value template to use. I just want to store a value persistently (including beyond a reboot).

zinc field
#

I don't know why it wants a min and max, but just give the biggest range

#

You can just ignore them

stoic vigil
#

What is the range of an energy sensor in kWh?

zinc field
#

0 to 10000000

#

Just give it a range and ignore it

stoic vigil
#

So what is the range for if I can ignore it? Just to configure the slider for the GUI?

#

I've set up an input number now, but I'm having trouble setting up the action to write to it.
Adapting the solution from this post I added an action block:

- actions:
  - action:
    - variables:
      target_charge: >-
        {{ states('sensor.zb_plug_ts011fp3_20a_02_energy') | int(0) }}
    - service: number.set_value
      target: 
        entity_id: input_number.xxxenergyonpreviousrun
      data:
        value: '{{ target_charge }}'```
But it is giving me an error I don't know how to interpret:
> The automation "xxx" (automation.xxx) is not active because the configuration has errors.
> 
> Error:value should be a string for dictionary value @ data['actions'][1]['action']. Got [{'variables': None, 'target_charge': "{{ states('sensor.zb_plug_ts011fp3_20a_02_energy') | int(0) }}"}, {'service': 'number.set_value', 'target': {'entity_id': 'input_number.xxxenergyonpreviousrun'}, 'data': {'value': '{{ target_charge }}'}}].
zinc field
#

You need to indent the line under variables:

#

Number is not input_number

#

Seems like you're mixing them up

stoic vigil
#

Thanks, yeah, I didn't realize number and input_number are different animals...

  - action:
    -  service: input_number.set_value
       data_template:
         entity_id: input_number.xxxenergyonpreviousrun
         value: "{{ states('sensor.zb_plug_ts011fp3_20a_02_energy') }}"```
still gives me an error like above and I don't see where I'm going wrong with the indentation.
> Error:value should be a string for dictionary value @ data['actions'][1]['action']. Got [{'service': 'input_number.set_value', 'data_template': {'entity_id': 'input_number.xxxenergyonpreviousrun', 'value': "{{ states('sensor.zb_plug_ts011fp3_20a_02_energy') }}"}}].
zinc field
#

You have both action: and service:

stoic vigil
#

Ah, thanks, now I get it. service is on the same level as action, both under actions.

zinc field
#

action: replaced service: several releases ago