Using current price compared to average price to cut electricity price peak, help!

Hi

I need some help with Template IF/ELSE logic.

RPI 4, Home Assistant Core Installed version 2022.5.2

I´m trying to make an automation starting and stopping my circulation pump for my underfloor heating when the electricity price (from Tibber) is higher than 20% of the average price of the day (since I’m a beginner I want to start with something and take if from there, I know there is more sophisticated ways but for me it would be a great start).

I have used this automation https://www.home-assistant.io/integrations/tibber/ and made adjustments to it to fit my needs (so I thought). I’m testing my code in the developer tool template, and it gives me a true or false value.

{{ float(states('sensor.electricity_price_XXX_33')) > 1.2 * float(state_attr('sensor.electricity_price_XXX_33', 'avg_price')) }}

I have looked at this video https://www.youtube.com/watch?v=GnW0mLt2YLg(Home Assistant Templates - A Beginner's Guide - YouTube) abt Template with IF/ELSE and also adjusted my code with {% etc but it just returns error:

Error message “TypeError: ‘<’ not supported between instances of ‘str’ and ‘float’

{% if states('sensor.electricity_price_XXX_33') > 1.2 * float(state_attr('sensor.electricity_price_XXX_33', 'avg_price')) %}

True

{% else %}

False

{% endif %}

When using the first code {{ float(states(‘sensor.electricity_price_XXX_33’)) > 1.2 * float(state_attr(‘sensor.electricity_price_XXX_33’, ‘avg_price’)) }} trying to create a automation it just turning on and of the pump every hour. I´m using a template as a trigger and time pattern 1 minute (just like the tibber high electricity price code).

alias: PUMP OFF

description: ''

trigger:

- platform: time_pattern

minutes: '1'

- platform: template

value_template: >-

{{ float(states('sensor.electricity_price_XXX_33')) > 1.2 *

float(state_attr('sensor.electricity_price_XXX_33',

'avg_price')) }}

condition: []

action:

- type: turn_off

device_id: c0f2acc5612c16f37b0e9c1ac947b543

entity_id: switch.PUMP_shelly

domain: switch

mode: single

I have also an automation for turning the pump ON and it would obviously be much better if it would be just one automation turning the pump on or off.

So, if anyone could point me in the right direction how i should uptade my code it would be much appreciated!

And sorry if my post is a bit all over the place and not up to standard, like i said im a totally beginner at this

Best regards Pontus

1 Like

Hey,

I have similar issue. Did you ever manage to solve this?

Thank you,

-Tapio