Help with input_text config

I am using the script below to make my Nest to go into Eco when triggered by an Automation and then go back to the last setting prior to the triggering. I think I am doing something wrong with my input_text since it is returning a state of unknown. I have added the input_text config below

nest_eco_on:
alias: Nest Thermostat - Set to ECO mode
sequence:
  # Only turn on ECO mode if thermostat is not off and not already in ECO
  # mode.
  - condition: template
    value_template: >
      {{ states('sensor.kitchen_thermostat_hvac_mode')
         not in ['off', 'eco'] }}

  - service: input_text.set_value
    entity_id: input_text.previous_hvac_mode
    data_template:
      value: "{{ states('sensor.kitchen_thermostat_hvac_mode') }}"

  - service: climate.set_preset_mode
    entity_id: climate.kitchen
    data:
      preset_mode: eco
nest_eco_off:
  alias: Nest Thermostat - Return from ECO mode
  sequence:
  # Only set back to previous mode if thermostat is still in ECO mode.
  - condition: template
    value_template: >
    {{ is_state('sensor.kitchen_thermostat_hvac_mode', 'eco') }}

  - service: climate.set_hvac_mode
    entity_id: climate.kitchen
    data_template:
      hvac_mode: "{{ states('input_text.previous_hvac_mode') }}"

this is the input_text

input_text:
  previous_hvac_mode:
    name: previous hvac mode
   pattern: "cool, heat, eco, off, away, auto"
   initial: "auto"

The scripts seem to be working but since it says unknown in the input text it cant complete the cycle.

My guess is sensor.kitchen_thermostat_hvac_mode doesn’t actually exist…

“unknown” is not in [‘off’, ‘eco’] either, so it will pass the condition. Might as well add “unknown” to the list so at least you don’t break things.

“unknown” is the return value of of the states() function if the entity can’t be found.

states(‘this_doesnt_exist’) == “unkonwn”


wait, actually,

That pattern is completely wrong. If you want to use a pattern, you need to specify a regex. Not just a list of words it could be.

Just remove the pattern, and add ‘unknown’ to the condition template. Or if you must, put a valid regex pattern…

Maybe this would work? Not sure…I’d just remove it completely. There’s no reason to match as you don’t care what the state was…you want to return to that state.

\b(?:cool|heat|eco|off|away|auto)\b

The sensor does exist and it works great but the input_text never returns the state it always reads unknown. I am not sure if it is properly set up

Have you looked at the logs?

I have I get two errors when running the off script
Nest Thermostat - Return from ECO mode: Error executing script. Invalid data for call_service at pos 2: value is not allowed for dictionary value @ data[‘hvac_mode’]

and this…

Error executing service <ServiceCall script.nest_eco_off (c:497b821b07f64db7acd5df0be098ed8d)>
Error executing service <ServiceCall script.nest_eco_off (c:03fa373a56a14ac19df61995c870b4b6)>
Traceback (most recent call last):
File “/usr/src/homeassistant/homeassistant/core.py”, line 1240, in _safe_execute
await self._execute_service(handler, service_call)
File “/usr/src/homeassistant/homeassistant/core.py”, line 1255, in _execute_service
await handler.func(service_call)
File “/usr/src/homeassistant/homeassistant/components/script/init.py”, line 207, in service_handler
await script.async_turn_on(variables=service.data, context=service.context)
File “/usr/src/homeassistant/homeassistant/components/script/init.py”, line 284, in async_turn_on
await self.script.async_run(kwargs.get(ATTR_VARIABLES), context)
File “/usr/src/homeassistant/homeassistant/helpers/script.py”, line 802, in async_run
await run.async_run()
File “/usr/src/homeassistant/homeassistant/helpers/script.py”, line 523, in async_run
await self._async_run()
File “/usr/src/homeassistant/homeassistant/helpers/script.py”, line 540, in _async_run
await self._async_step(log_exceptions=not propagate_exceptions)
File “/usr/src/homeassistant/homeassistant/helpers/script.py”, line 154, in _async_step
self, f"async{cv.determine_script_action(self._action)}_step"
File “/usr/src/homeassistant/homeassistant/helpers/script.py”, line 624, in _async_call_service_step
*self._prep_call_service_step(), blocking=True, context=self._context
File “/usr/src/homeassistant/homeassistant/core.py”, line 1210, in async_call
processed_data = handler.schema(service_data)
File “/usr/local/lib/python3.7/site-packages/voluptuous/validators.py”, line 208, in call
return self._exec((Schema(val) for val in self.validators), v)
File “/usr/local/lib/python3.7/site-packages/voluptuous/validators.py”, line 287, in _exec
raise e if self.msg is None else AllInvalid(self.msg, path=path)
File “/usr/local/lib/python3.7/site-packages/voluptuous/validators.py”, line 283, in _exec
v = func(v)
File “/usr/local/lib/python3.7/site-packages/voluptuous/schema_builder.py”, line 272, in call
return self._compiled([], data)
File “/usr/local/lib/python3.7/site-packages/voluptuous/schema_builder.py”, line 817, in validate_callable
return schema(data)
File “/usr/local/lib/python3.7/site-packages/voluptuous/schema_builder.py”, line 272, in call
return self._compiled([], data)
File “/usr/local/lib/python3.7/site-packages/voluptuous/schema_builder.py”, line 594, in validate_dict
return base_validate(path, iteritems(data), out)
File “/usr/local/lib/python3.7/site-packages/voluptuous/schema_builder.py”, line 432, in validate_mapping
raise er.MultipleInvalid(errors)
voluptuous.error.MultipleInvalid: value is not allowed for dictionary value @ data[‘hvac_mode’]

I dont see how it can return from Eco mode if the input_text never updates to anything though

Did you remove the pattern like I suggested?

sure did, same results state always says unknown

Can you set the input text in the dev tools > services menu?

input_text:
  previous_hvac_mode:
    name: previous hvac mode
   pattern: "cool, heat, eco, off, away, auto"
   initial: "auto"

your spacing looks wrong, but probably just a copy/paste error.

So I tried it your way and I got an error. So I tried this to see if it was a spacing error and it seems to be working. Thanks for pointing me in the right direction!!!

input_text:
  previous_hvac_mode:
    name: previous hvac mode
    pattern: "cool, heat, eco, off, away, auto"
    initial: "auto"
1 Like

Cool, glad it’s working!

This is why it’s recommended to use the ‘Preformatted Text’ option in the forums. It will preserve all spacing exactly as-is so it’s easier to find syntax errors. This is the </> button next to the qoutes button when typing a message. I initially just ignored the spacing because if you don’t use that, the forum often messes up spacing and makes it look wrong.

Or maybe you did use it, but the syntax highlighter was all messed up because the top level indentation was wrong? Who knows! I just make sure my text has red letters in it and that usually means it’s parsing something right lol.

I did use it my code was spaced wrong since the beginning Thanks again!!!