How to cycle throw colors with the press of a button

Hi,
I got an TS004F rotary knob to remotely control my LED light stripes. The goal is to use the ‘zigbee2mqtt/Stube MediaRemote/action’, payload ‘color_temperature_step_down’ and up to cycle throw colors.
There is a Blueprint for this knob, but just for ZHA, but I did not manage to get it running with Z2M.

There is an other one witch is a loop animation, but I did not manage to get this one working when trigered by a button instead by time.

Thanks for help:-)

Perhaps you can use this as the basis for a solution:

You will need to replace the example’s State Trigger with an MQTT Trigger.

Let me know if you need more help to compose the automation (or if the example doesn’t meet your requirements).

Hey Taras, thaks. Your way worked! Nice

Now I have 10 automations regarding this remote, one for each input action. Is there a way to put all thous automations in one?

Yes. Post three or more of the ten automations (or all ten) and I’ll show you how to consolidate them.

sweet, thaks!

alias: MediaRemote ColorDown
description: ""
trigger:
  - platform: device
    domain: mqtt
    device_id: e5edc01b727ac1a02a8cb44a6c2c1387
    type: action
    subtype: color_temperature_step_down
    discovery_id: 0x04cd15fffe23ecb2 action_color_temperature_step_down
condition: []
action:
  - service: light.turn_on
    data:
      color_name: "{{ states('input_select.colors_3') }}"
      brightness_pct: 100
    target:
      device_id: 98d1ca44296ab7a594b73e341a276340
  - service: input_select.select_next
    target:
      entity_id: input_select.colors_3
    data: {}
mode: parallel
alias: MediaRemote ColorUp
description: ""
trigger:
  - platform: device
    domain: mqtt
    device_id: e5edc01b727ac1a02a8cb44a6c2c1387
    type: action
    subtype: color_temperature_step_up
    discovery_id: 0x04cd15fffe23ecb2 action_color_temperature_step_up
condition: []
action:
  - service: light.turn_on
    data:
      color_name: "{{ states('input_select.colors_3') }}"
      brightness_pct: 100
    target:
      device_id: 98d1ca44296ab7a594b73e341a276340
  - service: input_select.select_previous
    target:
      entity_id: input_select.colors_3
    data: {}
mode: parallel
alias: MediaRemote decrease brightness
description: MediaRemote Light
trigger:
  - platform: device
    domain: mqtt
    device_id: e5edc01b727ac1a02a8cb44a6c2c1387
    type: action
    subtype: brightness_step_down
    discovery_id: 0x04cd15fffe23ecb2 action_brightness_step_down
condition: []
action:
  - device_id: 98d1ca44296ab7a594b73e341a276340
    domain: light
    entity_id: light.led_stripe_stube
    type: brightness_decrease
mode: parallel
alias: MediaRemote Increase Brightness
description: MediaRemote Light
trigger:
  - platform: device
    domain: mqtt
    device_id: e5edc01b727ac1a02a8cb44a6c2c1387
    type: action
    subtype: brightness_step_up
    discovery_id: 0x04cd15fffe23ecb2 action_brightness_step_up
condition: []
action:
  - device_id: 98d1ca44296ab7a594b73e341a276340
    domain: light
    entity_id: light.led_stripe_stube
    type: brightness_increase
mode: parallel
alias: MediaRemote Next
description: ""
trigger:
  - platform: device
    domain: mqtt
    device_id: e5edc01b727ac1a02a8cb44a6c2c1387
    type: action
    subtype: double
    discovery_id: 0x04cd15fffe23ecb2 action_double
condition: []
action:
  - service: media_player.media_next_track
    data: {}
    target:
      entity_id: media_player.hifiberry_192_168_1_21
mode: single
alias: MediaRemote PlayPause
description: ""
trigger:
  - platform: device
    domain: mqtt
    device_id: e5edc01b727ac1a02a8cb44a6c2c1387
    type: action
    subtype: single
    discovery_id: 0x04cd15fffe23ecb2 action_single
condition: []
action:
  - service: script.kodi_play_pause
    data: {}
mode: single
alias: MediaRemote VolumeDown
description: ""
trigger:
  - platform: device
    domain: mqtt
    device_id: e5edc01b727ac1a02a8cb44a6c2c1387
    type: action
    subtype: rotate_left
    discovery_id: 0x04cd15fffe23ecb2 action_rotate_left
condition: []
action:
  - service: media_player.volume_down
    data: {}
    target:
      entity_id: media_player.hifiberry_192_168_1_21
mode: parallel
alias: MediaRemote VolumeUP
description: ""
trigger:
  - platform: device
    domain: mqtt
    device_id: e5edc01b727ac1a02a8cb44a6c2c1387
    type: action
    subtype: rotate_right
    discovery_id: 0x04cd15fffe23ecb2 action_rotate_right
condition: []
action:
  - service: media_player.volume_up
    data: {}
    target:
      entity_id: media_player.hifiberry_192_168_1_21
mode: parallel

The examples you posted use MQTT Device Triggers. It’s simpler to consolidate automations employing MQTT Triggers.

To use an MQTT Trigger, we need to know the topic that the device publishes to and examples of the payloads that are published. I’ll take a guess that the payloads are rotate_right, rotate_left, single, double, etc but I’ll need to know the topic.

hmm, there are several things marked as topic:

Topic: homeassistant/sensor/0x04cd15fffe23ecb2/action/config
Payload
availability:
  - topic: zigbee2mqtt/bridge/state
device:
  identifiers:
    - zigbee2mqtt_0x04cd15fffe23ecb2
  manufacturer: TuYa
  model: Smart knob (ERS-10TZBVK-AA)
  name: Stube MediaRemote
enabled_by_default: true
icon: mdi:gesture-double-tap
json_attributes_topic: zigbee2mqtt/Stube MediaRemote
name: Stube MediaRemote action
state_topic: zigbee2mqtt/Stube MediaRemote
unique_id: 0x04cd15fffe23ecb2_action_zigbee2mqtt
value_template: '{{ value_json.action }}'
platform: mqtt

Yes, the payloads are the one stated by you, rotate_right and so on.

Here’s the general idea (it may require adjustments).

alias: MediaRemote Control
description: ""
mode: parallel
trigger:
  - platform: mqtt
    state_topic: zigbee2mqtt/Stube MediaRemote
condition: []
action:
  - variables:
      light: light.led_stripe_stube
      player: media_player.hifiberry_192_168_1_21
  - choose:
      - conditions: "{{ trigger.payload in ['color_temperature_step_down','color_temperature_step_up',] }}"
        sequence:
          - service: light.turn_on
            data:
              color_name: "{{ states('input_select.colors_3') }}"
              brightness_pct: 100
            target:
              entity_id: '{{ light }}'
          - service: "input_select.select_{{ 'next' if 'down' in trigger.payload else 'previous' }}"
            target:
              entity_id: input_select.colors_3
      - conditions: "{{ trigger.payload in ['brightness_step_down','brightness_step_up',] }}"
        sequence:
          - service: light.turn_on
            data:
              brightness_step_pct: "{{ -10 if 'down' in trigger.payload else 10 }}"
            target:
              entity_id: '{{ light }}'
      - conditions: "{{ trigger.payload == 'double' }}"
        sequence:
          - service: media_player.media_next_track
            target:
              entity_id: '{{ player }}'
      - conditions: "{{ trigger.payload == 'single' }}"
        sequence:
          - service: script.turn_on
            target:
              entity_id: script.kodi_play_pause
      - conditions: "{{ trigger.payload in ['rotate_left','rotate_right',] }}"
        sequence:
          - service: "media_player.volume_{{ 'down' if 'left' in trigger.payload else 'up' }}"
            target:
              entity_id: '{{ player }}'
    default: []

Each choice in choose handles one or two of the received commands:

  • color up/down
  • brightness up/down
  • double click
  • single click
  • rotate left/right
1 Like