Hi
how can I store 2 values in a text helper ? and how do I reference them individually later?
I need to store HVAC mode and current temperature, and later use those values to reset a thermostat
I have automations working for each thermostat with just the mode, but now I find I need to record / set the temperature too. My multiple helpers are already getting messy to manage
Thanks
Hi @Tdwdotnet
You could store the two values in the helper by concatenating the two string values. You could put a feminist character in the middle - maybe a bar symbol.
You can then use the Jinja split function to split the two values out.
123
(Taras)
March 2, 2024, 2:20pm
3
I’m unfamiliar with “feminist” used in this context. Is that an auto-correct goof or something else?
mekaneck
(Rick Auch)
March 2, 2024, 2:23pm
5
You could also get fancy with encoding values in JSON:
Use this in a template to set the values:
{{ dict(mode='heat', temp=70) | to_json }}
And this to extract them (this example just extracts ‘mode’)
{{ (states('input_text.json') | from_json).mode }}
123
(Taras)
March 2, 2024, 2:32pm
6
I see what you did there … but the suggested “feminist” example was a “bar symbol”.
I’m gonna go with “auto-correct goof” until templeton_nash clears it up. A vertical bar is easier to type than Unicode: U+2640.
heat|70
123
(Taras)
March 2, 2024, 2:34pm
8
Your auto-correct appears to be powered by ChatGPT …
1 Like
Edwin_D
(Edwin D.)
March 2, 2024, 2:42pm
9
This is a clever way to use attibutes to store many variables. Maybe that is a better way to prevent input helper explosion?
@123
Here you go, an updated version.
You can set a default setting if you want to store the timestamp or not in the default_timestamp attribute of the template sensor, but you can also overrule that setting using set_timestamp: true or set_timestamp: false in the event data
Updated code for the template sensor:
template:
- trigger:
- platform: event
event_type: set_variable
- platform: event
event_type: remove_variable
sensor:
- unique_id: 4a4c8e53-9e…
The one here also adds a timestamp, there’s a simpler version above if you do. ot need that:
here you go:
Trigger based template sensor:
template:
- trigger:
- platform: event
event_type: set_variable
- platform: event
event_type: remove_variable
sensor:
- unique_id: 4a4c8e53-9e68-4198-9cc5-b336e228ea4d
name: Variables
state: Variables
attributes:
variables: >
{% set current = this.attributes.get('variables', {}) %}
{% if trigger.event.event_type == 'set_variable' %}
{% set …
Thank you, I tried a few options but this worked best for me
- service: input_text.set_value
target:
entity_id: input_text.bedroom_window_helper
data:
value: >-
{{ dict(mode=states('climate.bedroom'),
temp=state_attr('climate.bedroom','temperature') ) | to_json
}}
and
- service: climate.set_hvac_mode
target:
entity_id: climate.bedroom
data:
hvac_mode: >-
{{ (states('input_text.bedroom_window_helper') |
from_json).mode }}