Hi.
I have a Sensor with data from Tibber.
- platform: rest
name: Tibber REST
resource: https://api.tibber.com/v1-beta/gql
method: POST
scan_interval: 60
payload: '{ "query": "{ viewer { homes { currentSubscription { priceInfo { today { total startsAt } tomorrow { total startsAt }}}}}}" }'
json_attributes_path: "$.data.viewer.homes[0].currentSubscription.priceInfo"
json_attributes:
- today
- tomorrow
value_template: "OK"
headers:
Authorization: !secret tibber_token
Content-Type: application/json
User-Agent: REST
It gets me a table like:
today:
- total: 0.1556
startsAt: '2024-08-25T00:00:00.000+02:00'
- total: 0.1552
startsAt: '2024-08-25T01:00:00.000+02:00'
- total: 0.1548
startsAt: '2024-08-25T02:00:00.000+02:00'
I would like to have the totals as cents not € so multiply by 100.
And startsAt is with an offset in timezone and i would like to have it calculate the hours into it.
I tryed a few things and searched for an answer but some are old and dont work with the syntax anymore and some dont work at all.
How would i do it?
I tryed with an template sensor like this:
strompreisvorschau:
friendly_name: Strompreisvorschau
value_template: >
{{ states('sensor.tibber_rest')}}
attribute_templates:
today: >
{% set today_data = state_attr('sensor.tibber_rest', 'today') %}
{% for entry in today_data %}
- total: {{ (entry.total * 100) | round(2) }}
startsAt: "{{ as_timestamp(entry.startsAt) | timestamp_local() }}"
{% endfor %}
tomorrow: >
{% set tomorrow_data = state_attr('sensor.tibber_rest', 'tomorrow') %}
{% for entry in tomorrow_data %}
- total: {{ (entry.total * 100) | round(2) }}
startsAt: "{{ as_timestamp(entry.startsAt) | timestamp_local() }}"
{% endfor %}
but the output is like:
today: - total: 15.56
startsAt: "2024-08-25T00:00:00+02:00"
- total: 15.52
startsAt: "2024-08-25T01:00:00+02:00"
- total: 15.48
startsAt: "2024-08-25T02:00:00+02:00"
- total: 15.4
startsAt: "2024-08-25T03:00:00+02:00"
the total seems to be correct but there are empty lines and the date is still wrong.
Can someone help me?