I would like to extract the raw_two_days
values from here, and pick the value which has the highest number (it’s the price for electricity). When I know the value, I would like to get the time for that occurrence, and that time should be the output of the template.
The reason is that I would like to start discharging my batteries when the price of the day peaks.
Sensor None has device class 'None', state class 'None' unit 'öre' and suggested precision 'None' thus indicating it has a numeric value; however, it has the non-numeric value: '[{'value': 26.927, 'start': datetime.datetime(2023, 10, 30, 0, 0, tzinfo=zoneinfo.ZoneInfo(key='Europe/Stockholm')), 'end': datetime.datetime(2023, 10, 30, 1, 0, tzinfo=zoneinfo.ZoneInfo(key='Europe/Stockholm'))}, {'value': 18.251, 'start': datetime.datetime(2023, 10, 30, 1, 0, tzinfo=zoneinfo.ZoneInfo(key='Europe/Stockholm')), 'end': datetime.datetime(2023, 10, 30, 2, 0, tzinfo=zoneinfo.ZoneInfo(key='Europe/Stockholm'))}, {'value': 17.192, 'start': datetime.datetime(2023, 10, 30, 2, 0, tzinfo=zoneinfo.ZoneInfo(key='Europe/Stockholm')), 'end': datetime.datetime(2023, 10, 30, 3, 0, tzinfo=zoneinfo.ZoneInfo(key='Europe/Stockholm'))}, {'value': 16.771, 'start': datetime.datetime(2023, 10, 30, 3, 0, tzinfo=zoneinfo.ZoneInfo(key='Europe/Stockholm')), 'end': datetime.datetime(2023, 10, 30, 4, 0, tzinfo=zoneinfo.ZoneInfo(key='Europe/Stockholm'))}, {'value': 25.114, 'start': datetime.datetime(2023, 10, 30, 4, 0, tzinfo=zoneinfo.ZoneInfo(key='Europe/Stockholm')), 'end': datetime.datetime(2023, 10, 30, 5, 0, tzinfo=zoneinfo.ZoneInfo(key='Europe/Stockholm'))}, {'value': 36.502, 'start': datetime.datetime(2023, 10, 30, 5, 0, tzinfo=zoneinfo.ZoneInfo(key='Europe/Stockholm')), 'end': datetime.datetime(2023, 10, 30, 6, 0, tzinfo=zoneinfo.ZoneInfo(key='Europe/Stockholm'))}, {'value': 86.048, 'start': datetime.datetime(2023, 10, 30, 6, 0, tzinfo=zoneinfo.ZoneInfo(key='Europe/Stockholm')), 'end': datetime.datetime(2023, 10, 30, 7, 0, tzinfo=zoneinfo.ZoneInfo(key='Europe/Stockholm'))}, {'value': 111.916, 'start': datetime.datetime(2023, 10, 30, 7, 0, tzinfo=zoneinfo.ZoneInfo(key='Europe/Stockholm')), 'end': datetime.datetime(2023, 10, 30, 8, 0, tzinfo=zoneinfo.ZoneInfo(key='Europe/Stockholm'))}, {'value': 118.909, 'start': datetime.datetime(2023, 10, 30, 8, 0, tzinfo=zoneinfo.ZoneInfo(key='Europe/Stockholm')), 'end': datetime.datetime(2023, 10, 30, 9, 0, tzinfo=zoneinfo.ZoneInfo(key='Europe/Stockholm'))}, {'value': 112.075, 'start': datetime.datetime(2023, 10, 30, 9, 0, tzinfo=zoneinfo.ZoneInfo(key='Europe/Stockholm')), 'end': datetime.datetime(2023, 10, 30, 10, 0, tzinfo=zoneinfo.ZoneInfo(key='Europe/Stockholm'))}, {'value': 107.404, 'start': datetime.datetime(2023, 10, 30, 10, 0, tzinfo=zoneinfo.ZoneInfo(key='Europe/Stockholm')), 'end': datetime.datetime(2023, 10, 30, 11, 0, tzinfo=zoneinfo.ZoneInfo(key='Europe/Stockholm'))}, {'value': 104.923, 'start': datetime.datetime(2023, 10, 30, 11, 0, tzinfo=zoneinfo.ZoneInfo(key='Europe/Stockholm')), 'end': datetime.datetime(2023, 10, 30, 12, 0, tzinfo=zoneinfo.ZoneInfo(key='Europe/Stockholm'))}, {'value': 103.051, 'start': datetime.datetime(2023, 10, 30, 12, 0, tzinfo=zoneinfo.ZoneInfo(key='Europe/Stockholm')), 'end': datetime.datetime(2023, 10, 30, 13, 0, tzinfo=zoneinfo.ZoneInfo(key='Europe/Stockholm'))}, {'value': 105.648, 'start': datetime.datetime(2023, 10, 30, 13, 0, tzinfo=zoneinfo.ZoneInfo(key='Europe/Stockholm')), 'end': datetime.datetime(2023, 10, 30, 14, 0, tzinfo=zoneinfo.ZoneInfo(key='Europe/Stockholm'))}, {'value': 117.719, 'start': datetime.datetime(2023, 10, 30, 14, 0, tzinfo=zoneinfo.ZoneInfo(key='Europe/Stockholm')), 'end': datetime.datetime(2023, 10, 30, 15, 0, tzinfo=zoneinfo.ZoneInfo(key='Europe/Stockholm'))}, {'value': 128.76, 'start': datetime.datetime(2023, 10, 30, 15, 0, tzinfo=zoneinfo.ZoneInfo(key='Europe/Stockholm')), 'end': datetime.datetime(2023, 10, 30, 16, 0, tzinfo=zoneinfo.ZoneInfo(key='Europe/Stockholm'))}, {'value': 138.262, 'start': datetime.datetime(2023, 10, 30, 16, 0, tzinfo=zoneinfo.ZoneInfo(key='Europe/Stockholm')), 'end': datetime.datetime(2023, 10, 30, 17, 0, tzinfo=zoneinfo.ZoneInfo(key='Europe/Stockholm'))}, {'value': 156.789, 'start': datetime.datetime(2023, 10, 30, 17, 0, tzinfo=zoneinfo.ZoneInfo(key='Europe/Stockholm')), 'end': datetime.datetime(2023, 10, 30, 18, 0, tzinfo=zoneinfo.ZoneInfo(key='Europe/Stockholm'))}, {'value': 146.184, 'start': datetime.datetime(2023, 10, 30, 18, 0, tzinfo=zoneinfo.ZoneInfo(key='Europe/Stockholm')), 'end': datetime.datetime(2023, 10, 30, 19, 0, tzinfo=zoneinfo.ZoneInfo(key='Europe/Stockholm'))}, {'value': 125.539, 'start': datetime.datetime(2023, 10, 30, 19, 0, tzinfo=zoneinfo.ZoneInfo(key='Europe/Stockholm')), 'end': datetime.datetime(2023, 10, 30, 20, 0, tzinfo=zoneinfo.ZoneInfo(key='Europe/Stockholm'))}, {'value': 90.023, 'start': datetime.datetime(2023, 10, 30, 20, 0, tzinfo=zoneinfo.ZoneInfo(key='Europe/Stockholm')), 'end': datetime.datetime(2023, 10, 30, 21, 0, tzinfo=zoneinfo.ZoneInfo(key='Europe/Stockholm'))}, {'value': 66.708, 'start': datetime.datetime(2023, 10, 30, 21, 0, tzinfo=zoneinfo.ZoneInfo(key='Europe/Stockholm')), 'end': datetime.datetime(2023, 10, 30, 22, 0, tzinfo=zoneinfo.ZoneInfo(key='Europe/Stockholm'))}, {'value': 49.705, 'start': datetime.datetime(2023, 10, 30, 22, 0, tzinfo=zoneinfo.ZoneInfo(key='Europe/Stockholm')), 'end': datetime.datetime(2023, 10, 30, 23, 0, tzinfo=zoneinfo.ZoneInfo(key='Europe/Stockholm'))}, {'value': 40.507, 'start': datetime.datetime(2023, 10, 30, 23, 0, tzinfo=zoneinfo.ZoneInfo(key='Europe/Stockholm')), 'end': datetime.datetime(2023, 10, 31, 0, 0, tzinfo=zoneinfo.ZoneInfo(key='Europe/Stockholm'))}]' (<class 'str'>)
The above is from attempting to use this:
{{ state_attr('sensor.ev_smart_charging_charging', 'raw_two_days') }}
These are all the states better formatted:
current_price: 105.64816625
EV SOC: 55
EV target SOC: 55
Charging is planned: false
Charging start time: null
Charging stop time: null
Charging number of hours: 0
raw_two_days:
- value: 26.927
start: '2023-10-30T00:00:00+01:00'
end: '2023-10-30T01:00:00+01:00'
- value: 18.251
start: '2023-10-30T01:00:00+01:00'
end: '2023-10-30T02:00:00+01:00'
- value: 17.192
start: '2023-10-30T02:00:00+01:00'
end: '2023-10-30T03:00:00+01:00'
- value: 16.771
start: '2023-10-30T03:00:00+01:00'
end: '2023-10-30T04:00:00+01:00'
- value: 25.114
start: '2023-10-30T04:00:00+01:00'
end: '2023-10-30T05:00:00+01:00'
- value: 36.502
start: '2023-10-30T05:00:00+01:00'
end: '2023-10-30T06:00:00+01:00'
- value: 86.048
start: '2023-10-30T06:00:00+01:00'
end: '2023-10-30T07:00:00+01:00'
- value: 111.916
start: '2023-10-30T07:00:00+01:00'
end: '2023-10-30T08:00:00+01:00'
- value: 118.909
start: '2023-10-30T08:00:00+01:00'
end: '2023-10-30T09:00:00+01:00'
- value: 112.075
start: '2023-10-30T09:00:00+01:00'
end: '2023-10-30T10:00:00+01:00'
- value: 107.404
start: '2023-10-30T10:00:00+01:00'
end: '2023-10-30T11:00:00+01:00'
- value: 104.923
start: '2023-10-30T11:00:00+01:00'
end: '2023-10-30T12:00:00+01:00'
- value: 103.051
start: '2023-10-30T12:00:00+01:00'
end: '2023-10-30T13:00:00+01:00'
- value: 105.648
start: '2023-10-30T13:00:00+01:00'
end: '2023-10-30T14:00:00+01:00'
- value: 117.719
start: '2023-10-30T14:00:00+01:00'
end: '2023-10-30T15:00:00+01:00'
- value: 128.76
start: '2023-10-30T15:00:00+01:00'
end: '2023-10-30T16:00:00+01:00'
- value: 138.262
start: '2023-10-30T16:00:00+01:00'
end: '2023-10-30T17:00:00+01:00'
- value: 156.789
start: '2023-10-30T17:00:00+01:00'
end: '2023-10-30T18:00:00+01:00'
- value: 146.184
start: '2023-10-30T18:00:00+01:00'
end: '2023-10-30T19:00:00+01:00'
- value: 125.539
start: '2023-10-30T19:00:00+01:00'
end: '2023-10-30T20:00:00+01:00'
- value: 90.023
start: '2023-10-30T20:00:00+01:00'
end: '2023-10-30T21:00:00+01:00'
- value: 66.708
start: '2023-10-30T21:00:00+01:00'
end: '2023-10-30T22:00:00+01:00'
- value: 49.705
start: '2023-10-30T22:00:00+01:00'
end: '2023-10-30T23:00:00+01:00'
- value: 40.507
start: '2023-10-30T23:00:00+01:00'
end: '2023-10-31T00:00:00+01:00'
charging_schedule:
- start: '2023-10-30T00:00:00+01:00'
end: '2023-10-30T01:00:00+01:00'
value: 0
- start: '2023-10-30T01:00:00+01:00'
end: '2023-10-30T02:00:00+01:00'
value: 0
- start: '2023-10-30T02:00:00+01:00'
end: '2023-10-30T03:00:00+01:00'
value: 0
- start: '2023-10-30T03:00:00+01:00'
end: '2023-10-30T04:00:00+01:00'
value: 0
- start: '2023-10-30T04:00:00+01:00'
end: '2023-10-30T05:00:00+01:00'
value: 0
- start: '2023-10-30T05:00:00+01:00'
end: '2023-10-30T06:00:00+01:00'
value: 0
- start: '2023-10-30T06:00:00+01:00'
end: '2023-10-30T07:00:00+01:00'
value: 0
- start: '2023-10-30T07:00:00+01:00'
end: '2023-10-30T08:00:00+01:00'
value: 0
- start: '2023-10-30T08:00:00+01:00'
end: '2023-10-30T09:00:00+01:00'
value: 0
- start: '2023-10-30T09:00:00+01:00'
end: '2023-10-30T10:00:00+01:00'
value: 0
- start: '2023-10-30T10:00:00+01:00'
end: '2023-10-30T11:00:00+01:00'
value: 0
- start: '2023-10-30T11:00:00+01:00'
end: '2023-10-30T12:00:00+01:00'
value: 0
- start: '2023-10-30T12:00:00+01:00'
end: '2023-10-30T13:00:00+01:00'
value: 0
- start: '2023-10-30T13:00:00+01:00'
end: '2023-10-30T14:00:00+01:00'
value: 0
- start: '2023-10-30T14:00:00+01:00'
end: '2023-10-30T15:00:00+01:00'
value: 0
- start: '2023-10-30T15:00:00+01:00'
end: '2023-10-30T16:00:00+01:00'
value: 0
- start: '2023-10-30T16:00:00+01:00'
end: '2023-10-30T17:00:00+01:00'
value: 0
- start: '2023-10-30T17:00:00+01:00'
end: '2023-10-30T18:00:00+01:00'
value: 0
- start: '2023-10-30T18:00:00+01:00'
end: '2023-10-30T19:00:00+01:00'
value: 0
- start: '2023-10-30T19:00:00+01:00'
end: '2023-10-30T20:00:00+01:00'
value: 0
- start: '2023-10-30T20:00:00+01:00'
end: '2023-10-30T21:00:00+01:00'
value: 0
- start: '2023-10-30T21:00:00+01:00'
end: '2023-10-30T22:00:00+01:00'
value: 0
- start: '2023-10-30T22:00:00+01:00'
end: '2023-10-30T23:00:00+01:00'
value: 0
- start: '2023-10-30T23:00:00+01:00'
end: '2023-10-31T00:00:00+01:00'
value: 0
- start: '2023-10-31T00:00:00+01:00'
end: '2023-10-31T01:00:00+01:00'
value: 0
- start: '2023-10-31T01:00:00+01:00'
end: '2023-10-31T02:00:00+01:00'
value: 0
- start: '2023-10-31T02:00:00+01:00'
end: '2023-10-31T03:00:00+01:00'
value: 0
- start: '2023-10-31T03:00:00+01:00'
end: '2023-10-31T04:00:00+01:00'
value: 0
- start: '2023-10-31T04:00:00+01:00'
end: '2023-10-31T05:00:00+01:00'
value: 0
- start: '2023-10-31T05:00:00+01:00'
end: '2023-10-31T06:00:00+01:00'
value: 0
- start: '2023-10-31T06:00:00+01:00'
end: '2023-10-31T07:00:00+01:00'
value: 0
- start: '2023-10-31T07:00:00+01:00'
end: '2023-10-31T08:00:00+01:00'
value: 0
- start: '2023-10-31T08:00:00+01:00'
end: '2023-10-31T09:00:00+01:00'
value: 0
- start: '2023-10-31T09:00:00+01:00'
end: '2023-10-31T10:00:00+01:00'
value: 0
- start: '2023-10-31T10:00:00+01:00'
end: '2023-10-31T11:00:00+01:00'
value: 0
- start: '2023-10-31T11:00:00+01:00'
end: '2023-10-31T12:00:00+01:00'
value: 0
- start: '2023-10-31T12:00:00+01:00'
end: '2023-10-31T13:00:00+01:00'
value: 0
- start: '2023-10-31T13:00:00+01:00'
end: '2023-10-31T14:00:00+01:00'
value: 0
- start: '2023-10-31T14:00:00+01:00'
end: '2023-10-31T15:00:00+01:00'
value: 0
- start: '2023-10-31T15:00:00+01:00'
end: '2023-10-31T16:00:00+01:00'
value: 0
- start: '2023-10-31T16:00:00+01:00'
end: '2023-10-31T17:00:00+01:00'
value: 0
- start: '2023-10-31T17:00:00+01:00'
end: '2023-10-31T18:00:00+01:00'
value: 0
- start: '2023-10-31T18:00:00+01:00'
end: '2023-10-31T19:00:00+01:00'
value: 0
- start: '2023-10-31T19:00:00+01:00'
end: '2023-10-31T20:00:00+01:00'
value: 0
- start: '2023-10-31T20:00:00+01:00'
end: '2023-10-31T21:00:00+01:00'
value: 0
- start: '2023-10-31T21:00:00+01:00'
end: '2023-10-31T22:00:00+01:00'
value: 0
- start: '2023-10-31T22:00:00+01:00'
end: '2023-10-31T23:00:00+01:00'
value: 0
- start: '2023-10-31T23:00:00+01:00'
end: '2023-11-01T00:00:00+01:00'
value: 0
icon: mdi:flash
Anyone know how to do that?
Thank you in advance!
EDIT:
OK, so I can now get 1 of the values, but I would like to either:
- Get all the values to be able to do some math
- Get the top value directly as an output
- Get the time when the max value occurs
{{ state_attr('sensor.ev_smart_charging_charging', 'raw_two_days')[1].value }}
cc @123 here since you seem to be an expert.