Goal : I am trying to have my Google Nest Mini read the number of minutes till the next bus in an automation
Here is what I have successfully done so far
I get the bus schedule from an open REST API with the following piece of code in my configuration.yaml :
sensor:
- platform: rest
resource: https://api-ratp.pierre-grimaud.fr/v4/schedules/buses/120/bry-sur-marne/R
name: RATP Bry
value_template: "{{ value_json.result.schedules[0].message[:-3] }}"
If you open the resource
url above, you’ll see a json like this :
{
"result": {
"schedules": [
{
"message": "11 mn",
"destination": "Nogent-Sur-Marne RER"
},
{
"message": "31 mn",
"destination": "Nogent-Sur-Marne RER"
}
]
},
"_metadata": {
"call": "GET /schedules/buses/120/bry-sur-marne/R",
"date": "2021-08-14T19:40:55+02:00",
"version": 4
}
}
My value_template
(trimmed with [:-3]) would then return 11 in that case (the number of minutes till the next bus)
In my automation, I expect to trigger it with a physical switch eventually but in the mean time, I’ve been testing with a dummy trigger that does work :
platform: state
entity_id: sensor.ratp_bry
from: '12'
to: '11'
Yes, it’s very clumsy but it proves to me that I can fetch the value in minutes from my value_template
In the Actions of my automation, I would like to have something like this (following code NOT working) :
service: tts.google_say
data:
message: Bus coming in {{ value_template }} minutes
entity_id: media_player.salon
(note : if I remove {{ value_template }}
from the message above, my speaker does talk to me)
What would be the correct syntax to call the number 11 in that message
?