Template help state_attr

can you help me with this template

{{ state_attr('sensor.energi_data_service','current_price')|int, 0 > state_attr('sensor.energi_data_service','today_max')|int, 0  }}

I get this error

ValueError: Template error: int got invalid input ‘{‘hour’: datetime.datetime(2023, 11, 8, 17, 0, tzinfo=<DstTzInfo ‘Europe/Copenhagen’ CET+1:00:00 STD>), ‘price’: 3.194}’ when rendering template ‘{{ state_attr(‘sensor.energi_data_service’,‘current_price’)|int, 0 > state_attr(‘sensor.energi_data_service’,‘today_max’)|int, 0 }}’ but no default was specified

Can you post the attributes of that sensor? It looks like you are trying to convert a datetime into an int.


image

its only the today_max price I will compare

{{ int(state_attr('sensor.energi_data_service','current_price'), 0) > int(state_attr('sensor.energi_data_service','today_max')['price'], 0)  }}
1 Like

cool. Thanks !