Input_number.set_value in Automation

I am trying to set the value in an Input Number from another Input Number value in an automation. I know it is something simple, but I can’t get it or find an example. I get an “expected float for dictionary value @ data[‘value’]” error. I have tried float and int attributes with no success.

Here is how I have it entered in the Automation

{
  "entity_id": "input_number.rain_yesterday",
  "value": "states(input_number.rain_probable)"
}

Here is what is shows in the automation. yaml file

- id: '1570109990433'
  alias: Advance Weather Data
  trigger:
  - at: '23:00:00'
    platform: time
  condition: []
  action:
  - data:
      entity_id: input_number.rain_yesterday
      value: states(input_number.rain_probable)
    service: input_number.set_value
1 Like

Try this:

  action:
  -  service: input_number.set_value
     data_template:
       entity_id: input_number.rain_yesterday
       value: "{{ states('input_number.rain_probable') }}"

(I’m not sure if the template needs to convert the value to integer)

Refer to the examples shown in the documentation. Here’s one that applies to your use-case:

  - alias: Set temp slider
    trigger:
      platform: mqtt
      topic: 'setTemperature'
    action:
      service: input_number.set_value
      data_template:
        entity_id: input_number.target_temp
        value: "{{ trigger.payload }}"
11 Likes

Still getting the same error. Also tried

“{{ input_number.rain_probable.state }}”

1 Like

Did you also change data: to data_template: like @123 said above?

Thank you and @123. I missed the data_template, I still had only data. Interesting it appears this can’t be entered in the Configuration -> Automation Editor and has to be entered in the automation.yaml. When I look at the automation in the Automation Editor it has {} in the Service Data. Is there a way to express data_template in the Developer Tools when testing Services?

I’d recommend not using the automation UI when creating automations. I’ve always just typed out the automations in straight yaml because I found the automation UI to be harder to use. Plus it helps you understand yaml syntax better.

I don’t think it’s possible to use templates in the Services dev tool, but I’m not fully sure about that. That being said, you could use the Templates dev tool to test the template first and then use the output from that in the Services dev tool.

1 Like

That is a good point. I think I get confused trying to write and automation using UI and then trying to correct it in automation.yaml.

Btw if you do move away from the UI editor, you will no longer need the id line, just an alias.

If you switch to the Visual Studio Code editor, it supports various Extensions to extend its functionality (this is fairly common for programming-oriented text editors). I would recommend installing the YAML extension (to validate YAML) and the Home Assistant Config Helper. It provides code-completion tailored for Home Assistant. For example, when creating an automation, it presents the available services in a list as well the entities you’ve defined.

The combination of these two extensions helps to minimize syntax errors.

3 Likes

Thanks- I like that option because I have used Visual Studio before. I tried the Hass.io Visual Studio Code Add-On previously and couldn’t get it working. Maybe not enough resources?

Hi,

I use the VsCode Home Assistant plugin successfully (I spent some times to do so)
My Home Assistant runs inside a Docker instance on a Raspberry Pi 3b+

VsCode runs on my Mac OS on which à mounted (with NFS) the homeassistant folder like this
sudo mount_nfs -o resvport [IP-RASPBERRY]:/usr/share/hassio/homeassistant /Users/[YOUR_MAC_USER]/[PATH_TO_MOUNT_POINT]/config

=> UID and GID must be the same on MAC and the Raspberry.

On VsCode I opened the config folder inside the NFS mounted directory (which is indeed the config folder of your home assistant on your PI).
I noticed that if I tried to open the home ‘home assistant’ directory the pluggin doesn’t work (too much latency).
I also noticed that sometimes I need to disable then enabled the plugin back.

Off course, you will need to configure correctly the plugin :

  • Vscode-home-assistant: http://[HASSIO_IP]:8123 (change the port if needed)
  • Vscode-home-assistant: Long Lived Access Token

Jeff

Hi,

I was hoping someone could help me with my problem.
I’m trying to calculate an integer to use as a countdown the next day.
The integer is being calculated (as float initially) with the following formula:

{{ ( (states(''sensor.pool_temp'')|float / 2) - (0,2 * states(''sensor.pool_temp'')|float)
        )  *3600 }} 

I’ve created an automation that was supposed to do this, but it’s not working.
My initial code looked like this:

- id: '1647120150029'
  alias: Zwembad bereken looptijd
  description: ''
  trigger:
  - platform: time
    at: '17:00:00'
  condition: []
  action:
  - service: input_number.set_value
    data:
      value: '{{ ( (states(''sensor.pool_temp'')|float / 2) - (0,2 * states(''sensor.pool_temp'')|float)
        )  *3600 }}'
    target:
      entity_id: input_number.pool_timer

When that didn’t do anything, I read this post and tried your suggestion above:

- id: '1647120150029'
  alias: Zwembad bereken looptijd
  description: ''
  trigger:
  - platform: time
    at: '17:00:00'
  condition: []
  action:
  - service: input_number.set_value
    data_template:
      entity_id: input_number.pool_timer
      value: {{ ( (states(''sensor.pool_temp'')|float / 2) - (0,2 * states(''sensor.pool_temp'')|float)
        )  *3600 }}

This didn’t even allow hass to restart anymore.

I tried putting everything in single and in double quotes, but nothing seems to work.
Where am i going wrong here?

afaik HA only knows DOTs as a Komma-replacement !

A bit late but this worked for me…

action:
  - service: input_number.set_value
    target:
      entity_id: input_number.electricity_day_rate
    data:
      value: "{{ states('input_number.electricity_upcoming_day_rate') }}"

Thanks so much, this really helped me out, years later !