Hey guys!
I’m trying to create an automation that triggers at a dynamically calculated time, based on the train delay and also the traffic sensor from Waze.
Let me be more clear: my father always takes the same train, which, according to the api of ViaggiaTreno, I have configured for tracking as a sensor in my HomeAssistant installation. In addition, I have setup another sensor (Waze Travel Time) that calculates the time needed to get to the train station.
Now, I would like my HomeAssistant to trigger an automation in time to get to the station, so it should check the delay of the train (it’s given by the train sensor of ViaggiaTreno, the only problem is that it seems to output the number of minutes + the unit so something like this: 13 min) and if it is more than x minutes (let’s suppose 10, for convenience), will take in count of this and talk to me (using tts_google_say) when the train is arriving, again, by looking also at the Waze sensor so I won’t be late when the train gets to the station.
Now a concrete example to clarify:
Assumption: sensor of the train 1234 reports a delay of 15 min --> train arrival was scheduled at 19.00, will arrive for real at 19.15
(0. compare the attribute of the sensor of the train (arrival_time) with the actual time) I’m not sure it’s totally needed…
- check the travel time to the station (Waze sensor), let’s suppose 5 minutes
- calculate the departure time so that I will arrive at the train station when the train gets there (according to its delay), so in this case should be something like this: 19.15 (real arrival) - 5 min (traffic based on the sensor) --> triggers my Google Home Mini (tts_google_say) at 19.10 (maybe a couple of minutes before could be better)
I know it’s a bit complex but I seriously would like this to work since it would help me a lot in my everyday routine.
Here is the core of the automation I’ve tried to setup but seems like it’s not working the part of the delay (I suppose because of the output of the train sensor (digits + min). I think a possible solution would be something like exploding the string based on the space separator between digits and chars but I totally don’t know how.
Any help is truly appreciated.
Thanks guys.
automation 1 (Waze travel time) I’m using this to know if there’s traffic on my way to the station
alias: railway station alert
trigger:
- above: '10'
entity_id: sensor.percorso_stazione
platform: numeric_state
condition: # I need it to trigger only in certain hours, not every day
- after: 19:00:00
before: 21:00:00
condition: time
- condition: state
entity_id: binary_sensor.workday_sensor
state: 'on'
action:
- data:
message: Seems like that's a bit more traffic than usual, on your way to the train station
service: tts.google_say
automation 2 (train delay based on ViaggiaTreno)
alias: train delay alert
trigger:
- above: '10'
entity_id: sensor.train_10658
platform: numeric_state
condition: # I need it to trigger only in certain hours, not every day
- after: '19:00:00'
before: '21:00:00'
condition: time
action:
- data_template:
message: "Looks like the train is {{states('sensor.train_10658')}} minutes late"
cache: false
service: tts.google_say
I’m trying to merge this two automations inside one and do the right modifications to make them work properly.