@miaucl I have installed the SBB Integration that is linked to the transportation schedule in Switzerland. I have set up a service and it tells me in how many minutes the next bus I am interested in is coming. And it also gives the next 2 scheduled busses, too. I wanted to create an automation that made the light turn color when the bus is coming in 5 minutes. I chose the departure entity and assigned a numeric state of below 5 (I assume this is in minutes) to trigger the automation. Because the time stamps are text I created a template in config.YAML to make a new entity called bus time remaining then used it in the automation.
template:
- sensor:
- name: "Bus Time Remaining"
unit_of_measurement: "minutes"
state: >
{% if states('sensor.xxx_to_yyy_departure') != 'unavailable' %}
{{ (as_timestamp(states('sensor.xxx_to_yyy_departure')) - as_timestamp(now())) // 60 }}
{% else %}
0
{% endif %}
Here is the yaml for the automation.
alias: Light To Yellow For Bus
description: ""
triggers:
- entity_id:
- sensor.bus_time_remaining
below: 5
trigger: numeric_state
conditions: []
actions:
- data:
scene_id: before_blink
snapshot_entities:
- light.jimmy_s_office_light_2
action: scene.create
- data:
rgb_color:
- 254
- 199
- 0
target:
entity_id:
- light.jimmy_s_office_light_2
action: light.turn_on
- delay:
seconds: 10
- data:
entity_id: scene.before_blink
action: scene.turn_on
mode: single
It also creates scene to go back to the original state of the light. I also wanted to make the light blink, but as it is an aqara ceiling light I am not sure that blinking is possible with a flash command. Anyway, the automation runs, but there is no light change. The traces come back clean but I get the feeling that it doesn’t recognize the 5 minutes. I am not an expert at yaml so it could all be wrong. I am fairly sure this should be possible. Perhaps there is another way. Any help or insight is appreciated.