Invalid data for call_service at pos 1: expected float for dictionary value @ data['value']

In home-assistant.log I get this every time I reboot.

2020-03-29 21:51:15 ERROR (MainThread) [homeassistant.components.automation] Error while executing automation automation.match_tv_vol_to_sonos_playbar_when_tv_vol_has_changed. Invalid data for call_service at pos 1: expected float for dictionary value @ data[‘value’]


- alias: 'Match TV Vol to Sonos Playbar when TV Vol has Changed'
  trigger:
    platform: state
    entity_id: media_player.livingroom_tv
  condition:
    - condition: template
      value_template: '{{ states.input_number.living_room_volume.state != states.media_player.livingroom_tv.attributes.volume_level}}'
  action:
    - service: input_number.set_value
      data_template:
        entity_id: input_number.living_room_volume
        value: "{{ state_attr('media_player.livingroom_tv', 'volume_level') }}"  
    - service: media_player.volume_set
      data_template:
        entity_id: media_player.tv_sonos
        volume_level: "{{ states.input_number.living_room_volume.state }}"

Any ideas?

value: "{{ state_attr('media_player.livingroom_tv', 'volume_level')|float }}" 
2 Likes

you need to pipe the value of the first service through float.

value: "{{ state_attr('media_player.livingroom_tv', 'volume_level')|float }}"  
2 Likes

Hello, same problem “expected float for dictionary value @ data[‘below’]” with:

alias: Katla temp uzturesana form
description: ''
trigger:
  - platform: numeric_state
    entity_id: sensor.atgaita_katls
    below: {{ states('weather.majas_hourly.temperature') | float * -1.4 + 34 }}
condition:
  - condition: time
    after: '8:00'
    before: '00:30'
  - condition: numeric_state
    entity_id: weather.majas_hourly
    attribute: temperature
    below: '0'
action:
  - service: climate.set_temperature
    data:
      temperature: 24.5
    entity_id: climate.netatmo_smart_thermostat
mode: single

[code removed, see below]

Still same problem…

I just realised, all I did was correct your template. I didn’t actually look at the trigger type.

That field cannot be templated, you can use a hard coded number or an input_number entity_id.

Thanks!
But I need, that this number will be dynamic…
How can I realize it?

trigger:
  platform: template
  value_template: >
    {{
      states('sensor.atgaita_katls')|float <
      states('weather.majas_hourly.temperature')|float * -1.4 + 34
    }}

Thanks, working well!

1 Like

Hi guys,
I need a little help: I have done a simple automation that keep track of minimum and maximum temperature during the day and reset value it at midnight with another automation.
I have the error in object (Invalid data for … etc.) and I cannot get rid of it. Following my automation code:

alias: Min Max Temperature
description: ''
trigger:
  - platform: state
    entity_id: sensor.temperature_2
condition: []
action:
  - service: input_number.set_value
    data_template:
      entity_id: input_number.minimum_temperature
      value: >
        {% if states('sensor.temperature_2')|float <
        states('input_number.minimum_temperature')|float
        %}{{states('sensor.temperature_2')|float}}{% endif %}
  - service: input_number.set_value
    data_template:
      entity_id: input_number.maximum_temperature
      value: >
        {% if states('sensor.temperature_2')|float >
        states('input_number.maximum_temperature')|float
        %}{{states('sensor.temperature_2')|float}}{% endif %}
mode: single

Sorry,
I was afraid about the syntax instead I made a dumb mistake, forgot to set the value in the else case. Fixed simply with:

service: input_number.set_value
data_template:
  entity_id: input_number.minimum_temperature
  value: >
    {% if states('sensor.temperature_2')|float <
    states('input_number.minimum_temperature')|float %}
    {{states('sensor.temperature_2')|float}}
    {% else %}
    {{states('input_number.minimum_temperature')|float}}
    {% endif %}