Avoid using states.sensor.temperature.state , instead use states('sensor.temperature') . It is strongly advised to use the states() , is_state() , state_attr() and is_state_attr() as much as possible, to avoid errors and error message when the entity isn’t ready yet (e.g., during Home Assistant startup).
Invalid config for [sensor.template]: invalid template (TemplateSyntaxError: unexpected char "'" at 71) for dictionary value @ data['sensors']['gangen_varmeovn_kost_idag']['value_template']. Got "{{ states('sensor.gangen_varmeovn_cal_energy_daily')| float(0)*(states('sensor.strompris_kwh | float(0)) | round(2) }}". (See ?, line ?).
Invalid config for [sensor.template]: invalid template (TemplateSyntaxError: unexpected ')') for dictionary value @ data['sensors']['varmepumpe_time_pris']['value_template']. Got "{{ states('sensor.gangen_varmeovn_cal_energy_hourly')| float(0)*states('sensor.strompris_kwh')|float(0))|round(2) }}". (See ?, line ?).
I dont know why i have to use 2 different syntax in same type template ? one is valid with float(0)) and other is valid with float(0)
if i delete extra ) like float(0) then then template is valid
Invalid config for [sensor.template]: invalid template (TemplateSyntaxError: unexpected ')') for dictionary value @ data['sensors']['varmepumpe_kost_mnd']['value_template']. Got "{{ states('sensor.varmepumpe_forbruk_mnd')|float(0)*states('sensor.strompris_kwh')|float(0))|round(2) }}". (See ?, line ?).
if i add extra ) like float(0)) then then template is valid
Invalid config for [sensor.template]: invalid template (TemplateSyntaxError: unexpected '}', expected ')') for dictionary value @ data['sensors']['gangen_varmeovn_time_pris']['value_template']. Got "{{ (states('sensor.gangen_varmeovn_cal_energy_hourly')|float(0)*states('sensor.strompris_kwh')|float(0)|round(2) }}". (See ?, line ?).
Please post the entire code of the sensor. If this is a template sensor using the modern format, you should use state not value_template — but without the whole code we’re wasting time guessing.
Have a look at the excellent documentation (here, for example).
For the template itself, the brackets aren’t just something you randomly sprinkle in to see if it works. It can help to space things out a bit to understand what’s going on. Here’s the template from my prior post, and then again spaced out:
What is your goal with this? Both template sensors have errors, but they are also pointless because you’re using a datetime entity which already mirrors a timestamp sensor in regards to automations.
Thank you! I now get a result that isn’t “unknown”.
Should today_at use my system time or local time? It’s showing an hour earlier than the input which would be GMT. I’m in London and we’re now at BST, one hour ahead.
My system is set to London and it shows the correct current time.
I’ve tried adding local and as_local but neither resolve it.
today_at does use local time. If you’re timestamp isn’t showing up correctly then you aren’t using the correct time somewhere on your system. There were bugs in older versions of home assistant related to today_at, but they were fixed. So make sure you’re on the latest HA.
Based on another post from you @petro (clearly very in demand) I believe the +0000 at the end of the sensor is showing that it’s ignoring my local time zone and is reporting UTC.
Shouldn’t today_at handle that? If not, is there something I can add to your code above to fix?