Comparing sensor value to attribute value to set sensor as true (On) or not true (Off)

Hiya,

I’m trying to get my home battery to charge when the price is lowest in 24h and to discharge when price is highest in 24h.

I therefore need to compare the value from sensor “sensor.huis_electricity_price” to the attribute of the same sensor “Max price”.

How would I do this in the GUI? I tried, as a first step, a template sensor which unfortunately does not output a value. I then wanted to compare the huis_electricity_price sensor value to the value of this newly created sensor to create a true or false sensor so I can trigger an automation.

{{ state_attr(‘huis_electricity_price’, ‘Max_price’) | float }}

Double check in the States tool for the actual attribute ID… it’s likely supposed to be max_price, the More Info menu shows a “pretty” version.

Also, the entity ID in the template is incomplete. It is missing it’s domain, it should be sensor.huis_electricity_price