Save attribute in a input number

Hi,

Im trying to create an automation that saves the current temperature to an input_number. Then sets the temperature to +1 degrees and after 1 hour I want the temperature to be set back to the value that has been saved in the input_number.

I tried it first in Node red but that was way to difficuld.
Thanks to some blueprints on this forum I created a service that should be the missing piece of my puzzle. Only it doesnt work.

What is going wrong in this service?

service: input_number.set_value
data: 
  value: {{ state_attr('climate.bosch', 'temperature') }}
target:
  entity_id: input_number.temp_helper

The line ā€œ{{ state_attr(ā€˜climate.boschā€™, ā€˜temperatureā€™) }}ā€ works when i use it as a template.
If I use ā€œvalue: 22ā€ it works.
But if i put these 2 together it fails.

You havenā€™t showed us how you do that.

Also, Iā€™m not sure the attributes you set will survive a restart.

Use doublequotes.

data: 
  value: "{{ state_attr('climate.bosch', 'temperature') }}"

Wow the double quotes works. Awesome.
Still dont really understand why those quotes are needed but with a littlebit of trail and error this will help me a lot!

Now I can continue to get the automation working

yep thoses bloody Quotes

My rule is " double quote on the outsides and single in the middle

"{{ bla'fgf'}}"

think it this way
when it see the first Quote or double quote it look for the next to pair it off

so with using double Quote

"{{ state_attr('climate.bosch', 'temperature') }}"
 |-------------the logic to work out -----------|

so base on that this would look like
"{{ state_attr("climate.bosch", "temperature") }}"
|--------------|  do the logic on this bit ERROR does not make cents

you can also use single on the outside and double on the inside

 '{{ state_attr("climate.bosch", "temperature")|int }}'

my logic goes back to old school coding we used

10 PRINT ā€œHELLOā€
20 Goto 10

HELLO would get printed down the screen

There is also a third way that works and possibly a fourth, but not sure about the fourth so I will have to test it on the computer before I post it.

 '{{ state_attr(''climate.bosch'', ''temperature'')|int }}'

So you do double single ' in the middle.

Aah that makes sence somehow. Thanks for the explenation. I donā€™t have a coding background (only Excel VBA) so home assistant has a steep learning curve for me. But that is also part of the fun ofcourse.

It seems home assistant changes it to the method Hellis81 is using.
So both methods have the same result.

Whit this managed to complete my automation this morning and it works great.

- id: '1640695527608'
  alias: Verwarming tijdelijk omhoog 
  description: ''
  trigger:
  - platform: state
    entity_id: input_boolean.warmte_1_uur
    to: 'on'
  - platform: state
    entity_id: input_boolean.warmte_1_uur
    to: 'off'
  condition: []
  action:
  - choose:
    - conditions:
      - condition: state
        entity_id: input_boolean.warmte_1_uur
        state: 'on'
      sequence:
      - service: input_number.set_value
        data:
          value: '{{ state_attr(''climate.bosch'', ''temperature'') }} '
        target:
          entity_id: input_number.temp_helper
      - service: climate.set_temperature
        target:
          entity_id: climate.bosch
        data:
          temperature: '{{ state_attr(''climate.bosch'', ''current_temperature'')
            | round(1, "half", default) + 1 }}'
      - delay:
          hours: 1
          minutes: 0
          seconds: 0
          milliseconds: 0
      - service: input_boolean.turn_off
        target:
          entity_id: input_boolean.warmte_1_uur
    default:
    - service: climate.set_temperature
      target:
        entity_id: climate.bosch
      data:
        temperature: '{{ state_attr(''climate.bosch'', ''temperature'') + 1
          }}'
    - service: input_number.set_value
      target:
        entity_id: input_number.temp_helper
      data:
        value: 0
  mode: restart

Home Assistantā€™s Automation Editor does that; its preference is to use single-quotes outside the template and two consecutive single-quotes (not the same as a double-quote character) inside the template.

Automations composed with a text editor can use whatever convention you prefer. My preference is the same as what myle described (double-quotes outside, single-quotes inside).

If you use a line-continuation character, such as > or | to indicate the template begins on the next line, then outer quotes are not required. However, when employing a line-continuation, the template must be indented with respect to its option (itā€™s indented by two spaces in the example below).

data: 
  value: >
    {{ state_attr('climate.bosch', 'temperature') }}
1 Like