Last active
April 21, 2024 20:59
-
-
Save gtrabanco/6af76cdcd6f5bd1b54ba40694c302b0d to your computer and use it in GitHub Desktop.
Revisions
-
gtrabanco renamed this gist
Apr 21, 2024 . 1 changed file with 36 additions and 4 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -10,17 +10,18 @@ input_text: my_bus_line: name: "Mi línea de autobús" initial: "J" my_bus_stop: name: "Mi parada de autobús" initial: 4112 rest: - resource_template: https://www.tua.es/rest/estimaciones/{{ states('input_text.my_bus_stop') }} verify_ssl: false scan_interval: 60 sensor: - name: "Current Bus Estimated seconds" unique_id: "current_bus_eta" json_attributes_path: $.estimaciones.value[?(@.line == states('input_text.my_bus_line'))].vh_first json_attributes: - meters @@ -39,7 +40,23 @@ rest: {% else %} None {% endif %} - name: "Current Bus Estimated Time" unique_id: "current_bus_eta_hhmmss" json_attributes_path: $.estimaciones.value[?(@.line == states('input_text.my_bus_line'))].vh_first json_attributes: - meters - seconds value_template: >- {% set from_time = int(as_timestamp(states.sensor.current_bus_estimated_seconds.last_changed), 0) %} {% if from_time > 0 %} {% set eta = int(states('sensor.current_bus_estimated_seconds')) %} {% set eta_time = from_time + eta %} {{ eta_time | timestamp_custom("%H:%M:%S") }} {% else %} {{ None }} {% endif %} - name: "Next Bus Estimated Seconds" unique_id: "next_bus_eta" json_attributes_path: $.estimaciones.value[?(@.line == states('input_text.my_bus_line'))].vh_second json_attributes: - meters @@ -58,3 +75,18 @@ rest: {% else %} None {% endif %} - name: "Next Bus Estimated Time" unique_id: "next_bus_eta_hhmmss" json_attributes_path: $.estimaciones.value[?(@.line == states('input_text.my_bus_line'))].vh_second json_attributes: - meters - seconds value_template: >- {% set from_time = int(as_timestamp(states.sensor.next_bus_estimated_seconds.last_changed), 0) %} {% if from_time > 0 %} {% set eta = int(states('sensor.current_bus_estimated_seconds')) %} {% set eta_time = from_time + eta %} {{ eta_time | timestamp_custom("%H:%M:%S") }} {% else %} {{ None }} {% endif %} -
gtrabanco revised this gist
Mar 22, 2024 . 1 changed file with 6 additions and 3 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -11,9 +11,12 @@ input_text: my_bus_line: name: "Mi línea de autobús" initial: "A" my_bus_stop: name: "Mi parada de autobús" initial: 1218 rest: - resource_template: https://www.tua.es/rest/estimaciones/{{ states('input_text.my_bus_stop') }} verify_ssl: false scan_interval: 60 sensor: @@ -42,13 +45,13 @@ rest: - meters - seconds value_template: >- {% set my_bus_line = states('input_text.my_bus_line') %} {% set buses = value_json['estimaciones']['value'] | default([]) %} {% if buses %} {% for bus in value_json['estimaciones']['value'] %} {% set bus_line = bus['line'] | default("None") %} {% set eta = int(bus['vh_second']['seconds'], 0) %} {% if bus_line == my_bus_line %} {{ eta }} {% endif %} {% endfor %} -
gtrabanco revised this gist
Mar 22, 2024 . 1 changed file with 14 additions and 4 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -2,32 +2,42 @@ # You need to change "A" for whatever your line it is # You can view all default params information stop here: #. https://www.tua.es/es/lineas-y-horarios/paradas/uria-centro-1218.html?idLinea=6#paradasIda # homeassistant: # packages: # rest: !include tua.yaml input_text: my_bus_line: name: "Mi línea de autobús" initial: "A" rest: - resource: https://www.tua.es/rest/estimaciones/1218 verify_ssl: false scan_interval: 60 sensor: - name: "Current Bus" json_attributes_path: $.estimaciones.value[?(@.line == states('input_text.my_bus_line'))].vh_first json_attributes: - meters - seconds value_template: >- {% set my_bus_line = states('input_text.my_bus_line') | string %} {% set buses = value_json['estimaciones']['value'] | default([]) %} {% if buses %} {% for bus in value_json['estimaciones']['value'] %} {% set bus_line = bus['line'] | default("None") %} {% set eta = int(bus['vh_first']['seconds'], 0) %} {% if bus_line == my_bus_line %} {{ eta }} {% endif %} {% endfor %} {% else %} None {% endif %} - name: "Next Bus" json_attributes_path: $.estimaciones.value[?(@.line == states('input_text.my_bus_line'))].vh_second json_attributes: - meters - seconds -
gtrabanco created this gist
Mar 22, 2024 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,47 @@ # You need to change last param of the resource url for your stop number # You need to change "A" for whatever your line it is # You can view all default params information stop here: #. https://www.tua.es/es/lineas-y-horarios/paradas/uria-centro-1218.html?idLinea=6#paradasIda rest: - resource: https://www.tua.es/rest/estimaciones/1218 verify_ssl: false scan_interval: 60 sensor: - name: "Current Bus" json_attributes_path: $.estimaciones.value[?(@.line == "A")].vh_first json_attributes: - meters - seconds value_template: >- {% set my_line = "A" %} {% set buses = value_json['estimaciones']['value'] | default([]) %} {% if buses %} {% for bus in value_json['estimaciones']['value'] %} {% set bus_line = bus['line'] | default("None") %} {% set eta = int(bus['vh_first']['seconds'], 0) %} {% if bus_line == my_line %} {{ eta }} {% endif %} {% endfor %} {% else %} None {% endif %} - name: "Next Bus" json_attributes_path: $.estimaciones.value[?(@.line == "A")].vh_second json_attributes: - meters - seconds value_template: >- {% set my_line = "A" %} {% set buses = value_json['estimaciones']['value'] | default([]) %} {% if buses %} {% for bus in value_json['estimaciones']['value'] %} {% set bus_line = bus['line'] | default("None") %} {% set eta = int(bus['vh_second']['seconds'], 0) %} {% if bus_line == my_line %} {{ eta }} {% endif %} {% endfor %} {% else %} None {% endif %}