Need help with sensor template

I want calculate the difference between 2 sensor data.

This is part of my configuration.yaml:

sensor:
.
.
.
#Sensoren, um den prozentualen Unterschied zwischen 2 Luftfeuchtigkeitswerten zu berechnen
  - platform: template
    sensors:
      my_sensor:
        value_template: {{ (states('sensor.einfahrt_multisensor_absolutehumidity') | float / states('sensor.cave_bad_multisensor_absolutehumidity') | float*100) |round(2) }}

and I get this error:

Error loading /config/configuration.yaml: invalid key: "OrderedDict([("(states('sensor.einfahrt_multisensor_absolutehumidity') | float / states('sensor.cave_bad_multisensor_absolutehumidity') | float)*100 |round(2)", None)])"
in "/config/configuration.yaml", line 91, column 0.

When I try the code in developers tool/template everything is fine. I don`t know what I am doing wrong so please could someone give me an advice?
Thanks a lot.

1 Like
value_template: "{{ (states('sensor.einfahrt_multisensor_absolutehumidity') | float / states('sensor.cave_bad_multisensor_absolutehumidity') | float*100) |round(2) }}"

single line templates need to be wrapped in quotation marks. And they need to be the opposite typas any that are internal to the {{…}}.

1 Like

Thank you, you made my day, now it works. Have a nice weekend!

1 Like

Please mark finity’s post as the solution.

1 Like

Yes, of course. Sorry.

Hi,

I have a automation in the night. And my vacuum clean must clean the room, but only a few weeks a week.
But when I used the the cleaner manuell in the week at this day, the cleaner mussed not clean in the night again.
I only get a template with the laced. changed but not in Kombination with a State.
How is this possible?

Here is my Script:
alias: Rollladen WohnzimmertĂĽr Gute Nacht
description: Der Rollladen an der WohnzimmertĂĽr startet das Gute nacht Programm
trigger:

  • platform: numeric_state
    entity_id: cover.ra_rolladen_tur
    attribute: current_position
    below: 95
    condition:
  • condition: or
    conditions:
    • condition: sun
      after: sunset
    • condition: sun
      before: sunrise
      action:
  • service: lock.lock
    data: {}
    target:
    entity_id: lock.haustur
  • if:
    • condition: numeric_state
      entity_id: sensor.e2008_battery_level
      below: 50
      then:
    • service: media_player.play_media
      target:
      entity_id: media_player.homepod_wohnzimmer
      data:
      media_content_id: media-source://media_source/local/Auto_unter50.mp3
      media_content_type: audio/mpeg
      metadata:
      title: Auto_unter50.mp3
      thumbnail: null
      media_class: music
      children_media_class: null
      navigateIds:
      - {}
      - media_content_type: app
      media_content_id: media-source://media_source
  • delay:
    hours: 0
    minutes: 0
    seconds: 10
    milliseconds: 0
  • if:
    • type: is_open
      condition: device
      device_id: d8cb4f828c3c62ba1b97e0509d5a99ae
      entity_id: binary_sensor.wohnzimmertur_state_2
      domain: binary_sensor
      then:
    • wait_for_trigger:
      • type: not_opened
        platform: device
        device_id: d8cb4f828c3c62ba1b97e0509d5a99ae
        entity_id: binary_sensor.wohnzimmertur_state_2
        domain: binary_sensor
  • service: cover.close_cover
    data: {}
    target:
    area_id:
    - wohnzimmer
    - kuche
  • service: cover.open_cover
    data: {}
    target:
    entity_id: cover.markise
  • if:
    • condition: state
      state: open
      entity_id: sensor.sensor_fenstergriff_badezimmer_state_2
      attribute: value_state
      then:
    • service: notify.mobile_app_iphone
      data:
      message: Badezimmerfenster ist auf
  • if:
    • condition: state
      entity_id: input_boolean.jemand_da
      state: “on”
      then:
    • service: light.turn_on
      data: {}
      target:
      device_id: 153cd4cf44e97dcaf9781da85042af7b
      alias: Wenn jemand da ist, Kellerlicht an
  • if:
    • condition: time
      weekday:
      • thu
      • sat
      • tue
    • condition: template
      value_template: >-
      {{ (as_timestamp(now()) -
      as_timestamp(states.vacuum.r2104_cloud_742471.last_changed)) > 90000
      }}
      alias: Die letzte Ă„nderung am Staubsauger ca einen Tag her ist
      then:
    • device_id: 42bb230f132a7a85a21f8c40146f8225
      domain: select
      entity_id: select.r2104_cloud_742471_a_l
      type: select_option
      option: audio_play_sound
    • delay:
      hours: 0
      minutes: 4
      seconds: 0
      milliseconds: 0
    • service: vacuum.start
      data: {}
      target:
      device_id: 42bb230f132a7a85a21f8c40146f8225
      enabled: true
      alias: Staubsauger an Dienstagen, Samstagen und Donnerstag
  • delay:
    hours: 0
    minutes: 1
    seconds: 0
    milliseconds: 0
    enabled: false
  • type: turn_off
    device_id: 1a05ff0825a3847cf048a9019537e4b5
    entity_id: light.stehlampe_oben
    domain: light
  • type: turn_off
    device_id: 47e8d1e719f6a2fc94688fa835b072f2
    entity_id: light.stehlampe_unten_2
    domain: light
    mode: single