Twitch follower train automation

Hey everyone,

I am trying to set up an automation that changes my light in my room to visualize my Follower train on Twitch. Anyway I can’t seem to figure it out. I thought maybe someone could help.

I set up the Twitch integration and it works well. I can see my followers and everything.

This is the automation I came up with but it seems not to trigger.

The idea is: everytime the state for followers of the twitch sensor changes, the automation is triggered. It looks if I am streaming and if the state is now higher than before.

However as I said it doesn’t trigger. I think I might have made a mistake with the trigger itself.

Here is my yaml:

alias: Twitch new follower (Train)
description: ''
trigger:
  - platform: event
    event_type: state_changed
    event_data:
      entity_id: sensor.jlnbln
      attribute: followers
condition:
  - condition: state
    entity_id: sensor.jlnbln
    state: streaming
  - condition: template
    value_template: '{{ trigger.to_state.state | int > trigger.from_state.state | int }}'
action:
  - service: light.turn_on
    data:
      brightness_pct: 100
      rgb_color:
        - 100
        - 40
        - 39
    entity_id: light.office_light

Help would be much appreciated!
Cheers!

Your trigger is wrong, try this:

trigger:
  platform: state
  entity_id: sensor.jlnbln
  attribute: followers

Hey thanks for the reply.

I had it like that before, but it also didn’t work…

like this:

alias: Twitch new follower (Train)
description: ''
trigger:
  - platform: state
    entity_id: sensor.jlnbln
    attribute: followers
condition:
  - condition: state
    entity_id: sensor.jlnbln
    state: streaming
  - condition: template
    value_template: '{{ trigger.to_state.state | int > trigger.from_state.state | int }}'
action:
  - service: light.turn_on

Your second condition will never be true as you are comparing the state of the sensor before and afterthe change but you need to compare the state of the attribute followers of the sensor before and after the change.

Try something like this:

- condition: template
  value_template: '{{ trigger.to_state.attributes.followers | int > trigger.from_state.attributes.followers | int }}'