Sorry, I was probably a bit vague, although it was because I believe after a lot of testing that my problem lies within the relative_time component.
My sensor is a shell_command that outputs this to a .txt file (I added the text in the parentheses):
off (charging state)
71 (battery charge %)
disconnected (charging cable state)
84 (range in km)
3000 (outside temperature in C * 100)
2900 (inside temperature in C * 100)
2016-09-07T10:53:05.001+02:00 (time of last update from car)
And then I read these values into separate sensors using the command_line component like so:
- platform: command_line
name: Rekkevidde
command: “sed -n 4p /home/pi/eup.txt”
value_template: ‘{{ value | int }}’
unit_of_measurement: “km”
- platform: command_line
name: Utetemperatur
command: “sed -n 6p /home/pi/eup.txt”
value_template: ‘{{ value | multiply(0.01) | round(1) }}’
unit_of_measurement: “%”
- platform: command_line
name: Siste oppdatering
command: “sed -n 7p /home/pi/eup.txt”
value_template: ‘{{ as_timestamp(value) | timestamp_local}}’
(I skipped a few lines for brevity.)
This gives me sensors like this (with some customizations):
Now what I’m trying to do is convert the “Siste oppdatering” (Last update) to a relative time, but this seems impossible as the relative_time component will not process it whatever I do - I’ve tried many different iterations of the output, and it does not seem to work either from the config file or the development tools.
The relative_time component will not work on the following lines in the development tools either:
{{ relative_time(“2016-09-07 21:44:29.718119+00:00”) }}
{{ relative_time(1473238385.001) }}
In fact, the only way I’ve managed to get it to work is to specifically reference a last_updated field.
So my question is basically, is there any way to get a timestamp from a command line sensor and convert it to a relative time?
And as a quick bonus question, is there any way to read a multi-line response from a shell command without going the route through a text file like I have done? (My script to get data from the car gets all fields, so I would like to not have to run it 6 times every update as I want to avoid hammering the car data service.)
Thank you in advance:)
Preben