Quantcast
Channel: Configuration - Home Assistant Community
Viewing all articles
Browse latest Browse all 95919

Randomly working automation with input_text and template

$
0
0

@etxttul wrote:

Hi,

In Stockholm the local radio tweets traffic information. I use the quite standard scrape sensor to get it in to HA.

This is the sensor (that works fine)

  - platform: scrape
    name: Trafik P4 Stockholm
    resource: https://twitter.com/TrafikP4Sthlm
    select: ".js-tweet-text-container .tweet-text"

After using this sensor, I realized that it some days the latest tweet is only valid for minutes and I only see the latest. Therefore I build a stack of FIFO for the tweets using input_text.

To keep the interest, I start with the automation the randomly works then I will give you the full automation. Please note that the day and time part works.

As said, this works, some times!!!

  - data_template:
      entity_id: input_text.trafik_7
      value: "{{ states.sensor.trafik_p4_stockholm.state.split ('http') [0] }}"
    service: input_text.set_value

(tried without the “split” it is still working randomly)

Here is the full automation.

- id: '1580301033027'
  alias: test trafik
  description: ''
  trigger:
  - event_data:
      entity_id: sensor.trafik_p4_stockholm
    event_type: state_changed
    platform: event
  condition: []
  action:
#   - data_template:
#       entity_id: input_text.trafik_6
#       value: '{{ states.input_text.trafik_5.state }}'
#     service: input_text.set_value
#   - data_template:
#       entity_id: input_text.trafik_time_6
#       value: '{{ states.input_text.trafik_time_5.state }}'
#     service: input_text.set_value
  - data_template:
      entity_id: input_text.trafik_5
      value: '{{ states.input_text.trafik_4.state }}'
    service: input_text.set_value
  - data_template:
      entity_id: input_text.trafik_time_5
      value: '{{ states.input_text.trafik_time_4.state }}'
    service: input_text.set_value
  - data_template:
      entity_id: input_text.trafik_4
      value: '{{ states.input_text.trafik_3.state }}'
    service: input_text.set_value
  - data_template:
      entity_id: input_text.trafik_time_4
      value: '{{ states.input_text.trafik_time_3.state }}'
    service: input_text.set_value
  - data_template:
      entity_id: input_text.trafik_3
      value: '{{ states.input_text.trafik_2.state }}'
    service: input_text.set_value
  - data_template:
      entity_id: input_text.trafik_time_3
      value: '{{ states.input_text.trafik_time_2.state }}'
    service: input_text.set_value
  - data_template:
      entity_id: input_text.trafik_2
      value: '{{ states.input_text.trafik_1.state }}'
    service: input_text.set_value
  - data_template:
      entity_id: input_text.trafik_time_2
      value: '{{ states.input_text.trafik_time_1.state }}'
    service: input_text.set_value
  - data_template:
      entity_id: input_text.trafik_1
      value: '{{ states.input_text.trafik_7.state }}'
    service: input_text.set_value
  - data_template:
      entity_id: input_text.trafik_time_1
      value: '{{ states.input_text.trafik_time_7.state }}'
    service: input_text.set_value
  - data_template:
      entity_id: input_text.trafik_7
      value: "{{ states.sensor.trafik_p4_stockholm.state.split ('http') [0] }}"
    service: input_text.set_value
  - data_template:
      entity_id: input_text.trafik_time_7
      value: '{{ as_timestamp(states.sensor.trafik_p4_stockholm.last_changed)| timestamp_custom("%A %X") }}'
    service: input_text.set_value

As said, it is a stack first in first out, and it works, now and then:-(
The " time and date thing works fine.

If you are wondering here is the configuration.yaml.

input_text:
  trafik_1:
    name: Trafik 1
    initial: ' '
  trafik_2:
    name: Trafik 2
    initial: ' '
  trafik_3:
    name: Trafik 3
    initial: ' '
  trafik_4:
    name: Trafik 4
    initial: ' '
  trafik_5:
    name: Trafik 5
    initial: ' '
  trafik_6:
    name: Trafik 6
    initial: ' '
  trafik_7:
    name: Trafik 7
    initial: ' '

  trafik_time_1:
    name: Trafik time 1
    initial: ' '
  trafik_time_2:
    name: Trafik time 2
    initial: ' '
  trafik_time_3:
    name: Trafik time 3
    initial: ' '
  trafik_time_4:
    name: Trafik time 4
    initial: ' '
  trafik_time_5:
    name: Trafik time 5
    initial: ' '
  trafik_time_6:
    name: Trafik time 6
    initial: ' '
  trafik_time_7:
    name: Trafik time 7
    initial: ' '

Posts: 1

Participants: 1

Read full topic


Viewing all articles
Browse latest Browse all 95919

Trending Articles