Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Examples for IDFM #6

Open
jugla opened this issue Apr 17, 2022 · 6 comments
Open

Examples for IDFM #6

jugla opened this issue Apr 17, 2022 · 6 comments

Comments

@jugla
Copy link

jugla commented Apr 17, 2022

Here a template to get remaining time to next train/bus/...
It allows to get a curve .
Hereafter an example, with the sensor for train RERB at robinson station.
In configuration.yaml,

template:
 ## IDF mobilite
  - sensor:
      - name: rer_b_robinson_deltatime
        state: "{{ ( (as_timestamp(states('sensor.idfm_robinson_chatenay_malabry_any_0')) - as_timestamp(now()))/60.0 ) | round (2) }}"
        unit_of_measurement: 'min'
        state_class: measurement

And the results :
image
NB: on left side, the value is not relevant (due to test to find the right formula)

@drosoCode drosoCode pinned this issue Apr 17, 2022
@drosoCode
Copy link
Member

Here is also an example of automation that I came up with (to prevent me from being late to my appointments because the next train was in too much time)

alias: metro
description: "affiche un message donnant les horaires des prochains train (basé sur les informations temps réel et le temps de trajet jusqu'a la station) lorsqu'un evenement du calendrier approche et que vous etes encore chez vous"
trigger:
- platform: time_pattern
  hours: '*'
  minutes: /5
  seconds: '*'
condition:
- condition: state
  entity_id: binary_sensor.portable
  state: 'on'
- condition: state
  entity_id: calendar.cours
  state: 'off'
- "{{ (as_timestamp(state_attr('calendar.cours','start_time'), 0) - as_timestamp(now(), 0)) < (30*60) }}"
action:
- service: input_text.set_value
  data:
    value: '{% set t1 = ((as_timestamp(states(''sensor.le_kremlin_bicetre_la_courneuve_8_mai_1945_0''),
      0) - as_timestamp(now()))/60)|round %}
      {% set t2 = ((as_timestamp(states(''sensor.le_kremlin_bicetre_la_courneuve_8_mai_1945_1''),
      0) - as_timestamp(now()))/60)|round %}
      {% set t3 = ((as_timestamp(states(''sensor.le_kremlin_bicetre_la_courneuve_8_mai_1945_2''),
      0) - as_timestamp(now()))/60)|round %}

      {% if t1 >= 8 %}
      Prochain train dans {{ t1 }} min, le suivant dans {{ t2 }} min
      {% elif t2 >= 8 %}
      Prochain train dans {{ t2 }} min, le suivant dans {{ t3 }} min
      {% else %}
      Prochain train dans {{ t3 }} min
      {% endif %}
      '
  target:
    entity_id: input_text.afficheur_txt
mode: single

@jugla
Copy link
Author

jugla commented Apr 17, 2022

it's clever !

@jugla
Copy link
Author

jugla commented Apr 17, 2022

I don't know, if it is the right place. The error on dedicated train/bus line has to be displayed on several lines.
I use the custome interface (cf. HACS) Multiline-Entity-Card.
To modify the font size and color, I also use card-mod.

Then , I create the following card on dashboard (with sensor binary_sensor.idfm_rer_b_robinson_chatenay_malabry).
Manual card :

type: custom:multiline-entity-card
name: RER B Pb
entity: binary_sensor.idfm_rer_b_robinson_chatenay_malabry
attribute: description
show_name: true
card_mod:
  style: |
    ha-card .value {
      color: blue;
      font-size : 15px;
    }

The result (current RER B construction site) :
image

@drosoCode
Copy link
Member

Yes, I think that we could use this issue to share examples for this integration.

Thanks for sharing !

@drosoCode drosoCode changed the title [enhancement] idea for idfm documentation Examples for IDFM Apr 23, 2022
@Bashy
Copy link

Bashy commented Jan 6, 2024

Voilà la card que je me suis faite pour mes besoins :), custom:button-card est nécessaire pour que cela fonctionne, j'ai également dû copier en local les svg (images vectorielles) officielles RATP.

image

type: horizontal-stack
cards:
  - type: custom:button-card
    entity: binary_sensor.idfm_7_porte_de_choisy_paris
    show_state: false
    show_name: true
    show_icon: false
    show_label: true
    show_entity_picture: true
    label: |
      [[[
       function display(entity) {
         if(entity == "unknown") {
           return "<b style='color: #cc0000; animation: blink 5s ease infinite'>!</b>"
         }
         var entity_date = new Date(entity);
         var now = new Date().getTime();
         var sec = Math.floor(entity_date/1000);
         var now_m = Math.floor(now/1000);
         var diff = Math.floor((sec-now_m)/60)
         if(diff < 0) { return "<b style='animation: blink 3s ease infinite'>0</b>"  }
         return diff
       }
       return display(
        states['sensor.idfm_porte_de_choisy_paris_m7_nord'].state
      ) + " | " + display(
        states['sensor.idfm_porte_de_choisy_paris_m7_nord_2'].state
      );
      ]]]
    name: |
      [[[
       function display(entity) {
         if(entity == "unknown") {
           return "<b style='color: #cc0000; animation: blink 5s ease infinite'>!</b>"
         }
         var entity_date = new Date(entity);
         var now = new Date().getTime();
         var sec = Math.floor(entity_date/1000);
         var now_m = Math.floor(now/1000);
         var diff = Math.floor((sec-now_m)/60)
         if(diff < 0) { return "<b style='animation: blink 3s ease infinite'>0</b>"  }
         return diff
       }
       return display(
        states['sensor.idfm_porte_de_choisy_paris_m7_sud'].state
      ) + " | " + display(
        states['sensor.idfm_porte_de_choisy_paris_m7_sud_2'].state
      );
      ]]]
    entity_picture: /local/pic/m7.svg
    styles:
      label:
        - font-weight: 900
        - font-size: 1.4rem
        - opacity: 0.8
        - background: rgba(0, 0, 0, 0.75)
        - color: yellow
        - border-radius: 15%
        - padding: 3px
        - position: absolute
        - margin-bottom: 2.8rem
        - margin-right: 5rem
      name:
        - font-weight: 900
        - font-size: 1.4rem
        - opacity: 0.8
        - background: rgba(0, 0, 0, 0.75)
        - color: yellow
        - border-radius: 15%
        - padding: 3px
        - position: absolute
        - margin-top: 2.8rem
        - margin-left: 5rem
      entity_picture:
        - opacity: 0.9
        - width: 2.7rem
        - filter: >
            [[[

            if(states['binary_sensor.idfm_7_porte_de_choisy_paris'].state ==
            "on")

            return "blur(2px) grayscale(80%)";

            ]]]
      card:
        - height: 6rem
      state:
        - font-weight: bold
        - font-size: 1.4rem
        - opacity: 0.75
  - type: custom:button-card
    entity: binary_sensor.idfm_t3a_porte_de_choisy_paris
    show_state: false
    show_name: true
    show_label: true
    show_icon: false
    show_entity_picture: true
    entity_picture: /local/pic/t3a.svg
    label: |
      [[[
       function display(entity) {
         if(entity == "unknown") {
           return "<b style='color: #cc0000; animation: blink 5s ease infinite'>!</b>"
         }
         var entity_date = new Date(entity);
         var now = new Date().getTime();
         var sec = Math.floor(entity_date/1000);
         var now_m = Math.floor(now/1000);
         var diff = Math.floor((sec-now_m)/60)
         if(diff < 0) { return "<b style='animation: blink 3s ease infinite'>0</b>"  }
         return diff
       }
       return display(
        states['sensor.idfm_porte_de_choisy_paris_t3a_ouest'].state
      ) + " | " + display(
        states['sensor.idfm_porte_de_choisy_paris_t3a_ouest_2'].state
      );
      ]]]
    name: |
      [[[
       function display(entity) {
         if(entity == "unknown") {
           return "<b style='color: #cc0000; animation: blink 5s ease infinite'>!</b>"
         }
         var entity_date = new Date(entity);
         var now = new Date().getTime();
         var sec = Math.floor(entity_date/1000);
         var now_m = Math.floor(now/1000);
         var diff = Math.floor((sec-now_m)/60)
         if(diff < 0) { return "<b style='animation: blink 3s ease infinite'>0</b>"  }
         return diff
       }
       return display(
        states['sensor.idfm_porte_de_choisy_paris_t3a_est'].state
      ) + " | " + display(
        states['sensor.idfm_porte_de_choisy_paris_t3a_est_2'].state
      );
      ]]]
    styles:
      label:
        - font-weight: 900
        - font-size: 1.4rem
        - opacity: 0.8
        - background: rgba(0, 0, 0, 0.75)
        - color: yellow
        - border-radius: 15%
        - padding: 3px
        - position: absolute
        - margin-bottom: 2.8rem
        - margin-right: 5rem
      name:
        - font-weight: 900
        - font-size: 1.4rem
        - opacity: 0.8
        - background: rgba(0, 0, 0, 0.75)
        - color: yellow
        - border-radius: 15%
        - padding: 3px
        - position: absolute
        - margin-top: 2.8rem
        - margin-left: 5rem
      entity_picture:
        - opacity: 0.9
        - width: 2.7rem
        - background-color: white
        - border-radius: 20%
        - filter: >
            [[[

            if(states['binary_sensor.idfm_t3a_porte_de_choisy_paris'].state ==
            "on")

            return "blur(2px) grayscale(80%)";

            ]]]
      card:
        - height: 6rem
  - type: custom:button-card
    entity: binary_sensor.idfm_14_olympiades_paris
    show_state: false
    show_name: false
    show_icon: false
    show_label: true
    show_entity_picture: true
    label: |
      [[[
       function display(entity) {
         if(entity.state == "unknown") {
           return "?"
         }
         var entity_date = new Date(entity);
         var now = new Date().getTime();
         var sec = Math.floor(entity_date/1000);
         var now_m = Math.floor(now/1000);
         var diff = Math.floor((sec-now_m)/60)
         if(diff < 0) { return "<b style='animation: blink 3s ease infinite'>0</b>"  }
         return diff
       }
       return display(
        states['sensor.idfm_olympiades_paris_m14_nord'].state
      ) + " | " + display(
        states['sensor.idfm_olympiades_paris_m14_nord_2'].state
      );
      ]]]
    entity_picture: /local/pic/m14.svg
    styles:
      label:
        - font-weight: 900
        - font-size: 1.4rem
        - opacity: 0.8
        - background: rgba(0, 0, 0, 0.75)
        - color: yellow
        - border-radius: 15%
        - padding: 3px
        - position: absolute
        - margin-bottom: 2.8rem
        - margin-right: 5rem
      entity_picture:
        - opacity: 0.9
        - width: 2.7rem
        - filter: |
            [[[
            if(states['binary_sensor.idfm_14_olympiades_paris'].state == "on")
            return "blur(2px) grayscale(80%)";
            ]]]
      card:
        - height: 6rem
      state:
        - font-weight: bold
        - font-size: 1.4rem
        - opacity: 0.75

@drosoCode
Copy link
Member

To use advanced filtering for time entities, see this issue: #25

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants