Make state for automation

Hi

Can anyone help me with this. Have the code below and I need to make it so that home assistant know that the entity can be true or false.

In automation it’s unknown state etc. If a make it visible in Lovelace it’s visible as true or false. But not in automation.


template:
  - sensor:
      - name: "Elpris under medel"
        state: >
          {{float( state_attr( 'sensor.Nordpool_elpris' , 'current_price' ) ) < ( float( state_attr( 'sensor.Nordpool_elpris' , 'average' ) ) ) }}
  - sensor:
      - name: "Elpris över medel"
        state: >
          {{float( state_attr( 'sensor.Nordpool_elpris' , 'current_price' ) ) > ( float( state_attr( 'sensor.Nordpool_elpris' , 'average' ) ) ) }}
 
alias: Starta varmvattenberedare när elpris är under medel
description: ""
trigger:
  - platform: state
    entity_id:
      - sensor.elpris_under_medel
    to: "true"
condition:
  - condition: state
    entity_id: sensor.elpris_under_medel
    state: "true"
action:
  - type: turn_on
    device_id: 82cc2fed0a2155064c08dbf1c499781a
    entity_id: switch.varmvattenberedare
    domain: switch
mode: single