Hi!
I have a RESTful service that I use that collects information from my car (ignition, speed, location etc).
This is working great and is coded like this if anyone is interested:
- platform: rest
name: mf_car
resource: https://fleetpro.tvg.uk/api/v1/unit/list.json?key=xxxxxx&include=ignition
headers:
Content-Type: application/json
User-Agent: Home Assistant REST sensor
json_attributes:
- data
value_template: 'OK'
- platform: template
sensors:
mf_car_odometer:
friendly_name: Odometer
value_template: '{{ states.sensor.mf_car.attributes["data"]["units"][0]["mileage"] | multiply(0.000621371) | round(0)}}'
#device_class: temperature
unit_of_measurement: 'mi'
icon_template: 'mdi:counter'
mf_car_speed:
friendly_name: Speed
value_template: '{{ states.sensor.mf_car.attributes["data"]["units"][0]["speed"] }}'
#device_class: temperature
unit_of_measurement: 'kmh'
icon_template: 'mdi:speedometer'
mf_car_state:
friendly_name: "Milo's Car"
value_template: '{{ states.sensor.mf_car.attributes["data"]["units"][0]["movement_state"]["name"] }}'
icon_template: 'mdi:state-machine'
mf_car_state_since:
friendly_name: State Since
value_template: '{{ as_timestamp(strptime(states.sensor.mf_car.attributes["data"]["units"][0]["movement_state"]["start"], "%Y-%m-%dT%H:%M:%S")) | timestamp_custom("%d/%m/%y %H:%M") }}'
icon_template: 'mdi:calendar'
mf_car_last_update:
friendly_name: Last Update
value_template: '{{ as_timestamp(strptime(states.sensor.mf_car.attributes["data"]["units"][0]["last_update"], "%Y-%m-%dT%H:%M:%S")) | timestamp_custom("%d/%m/%y %H:%M") }}'
icon_template: 'mdi:update'
mf_car_ignition:
friendly_name: Ignition
value_template: '{{ states.sensor.mf_car.attributes["data"]["units"][0]["ignition"]["value"] }}'
icon_template: 'mdi:car-key'
mf_car_ignition_since:
friendly_name: Ignition Since
value_template: '{{ as_timestamp(strptime(states.sensor.mf_car.attributes["data"]["units"][0]["ignition"]["gmt"], "%Y-%m-%dT%H:%M:%S")) | timestamp_custom("%d/%m/%y %H:%M") }}'
icon_template: 'mdi:calendar'
The beauty of this is that it does the call itself, gets the data and puts it all into a load of sensors ready to use on lovelace. Great!
But… There is always room for improvement (or I am never happy with what I have).
I can get this data in real time via data forwarding from my cars system… so I’ve got an inbound webhook in automation setup that is receiving and reading data. I just dont know how to pass this data to create some sensors in the action of the automation. Anyone any ideas?