Electrical price , switch on/off

hello
i’m a pretty new user to HA so i’m still try to figure out how it works :stuck_out_tongue:
i´m trying to get a simple toggle switch depending on the current electrical price.
as according to

my configure is right now

 - alias: "Electricity price"
   trigger:
     platform: time_pattern
  * Matches every hour at 1 minutes past whole
     minutes: 1
   condition:
     condition: template
     value_template: '{{ float(states.sensor.electricity_price_ledetvagen_22.state) > 0.9 * float(states.sensor.electricity_price_ledetvagen_22.attributes.max_price) }}'
   action:
    - service: input_boolean.toggle
      data:
        entity_id: input_boolean.varmepump

i guess i have done some stupid mistakes trying to get this to work.

Welcome. Please read point 11 here and edit your post to format your pasted config: How to help us help you - or How to ask a good question

Edit: much better. Thank you. Try changing your template to this:

value_template: "{{ states('sensor.electricity_price_ledetvagen_22')|float > ( 0.9 * state_attr('sensor.electricity_price_ledetvagen_22', 'max_price')|float ) }}"

If that works you might consider using a template binary sensor instead of an automation, use the same template. It will update whenever either of the prices change.

1 Like

works like a charm! I made a binary sensor out of it and inverted the signal. thks for the quick anserw!

1 Like