Can I store 2 items in a single text helper

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.

I’m unfamiliar with “feminist” used in this context. Is that an auto-correct goof or something else?

Simple enough:

foo♀️bar

Then split('♀️').

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 }}

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

Feminist! Lol!

I meant delimiter.

2 Likes

Your auto-correct appears to be powered by ChatGPT …

1 Like

This is a clever way to use attibutes to store many variables. Maybe that is a better way to prevent input helper explosion?

The one here also adds a timestamp, there’s a simpler version above if you do. ot need that:

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  }} 

:slight_smile: