Hello, I’m trying to insert my own data and use it in the application. I generated values for each day and now I want to display them depending on the day.
{% set random = {
"data": [0,321,132,423]
} %}
{% set day = {
"day": 2
} %}
It is day number {{ day.day }}.
Todays data is {{ random.data[day.day] }}.
Output
It is day number 2.
Todays data is 132.
This works in development tools but I can’t figure it out how to correctly place it in configuration.
Could you please advise?
Thank you
Best Regards
Martin
Template sensor will do the job.
Hello David, thank you for quick response. I have teplate sensor configured to show current day for example. But I don’t know what is the correct form for adding the set of data.
Thank you
Best Regards
Martin
Try this:
sensor:
- platform: template
sensors:
random_day:
value_template: >-
{% set random = {"data": [0,321,132,423]} %}
{% set day = {"day": 2} %}
It is day number {{ day.day }}, Todays data is {{ random.data[day.day] }}.
If you want it on 2 lines you might need 2 sensors but try it…
Hello David, thank you for that. It really worked! Now I am struggling with implementing the day number which I have in different sensor.
sensors:
days:
value_template: '{{ ((as_timestamp(now())-(states.input_datetime.birthday.attributes.timestamp)) | int /60/1440) | round(0) }}'
unit_of_measurement: 'days'
Is it possible to use value for {{ day.day }} from different source?
Thank you
Best Regards
Martin
If that is creating sensor.days then states(‘sensor.days’) will use that sensor.
Hello David, random.data [states (‘sensor.days’)] does not work. I assume that the value given by this sensor is in the form of a string while the value […] expects a number.
Is it possible to convert a sensor value from a string to a number?
Thank you
Best Regards
Martin
Replace sensor.days with whatever your actual sensor is
Hello David, I just added | int
{{random.data[states("sensor.days") | int]}}
and it worked!
Thank you again for your help.
Best Regards
Martin
1 Like