How to trap the level of one device, and telling another to be the same value (0-255)

I have a CBUS system, which I integrate via Home Bridge and into HA. I’m a new HA user (less than a week) but already I can see it has so much potential to work with my systems. So, the piece above works flawlessly.

What I want to do is trap the level of the incoming CBUS device into HA (0-255 as a dimmer) then be able to tell a script or automation to set another device to the very same level, in this case some Shelly dimmers.

I have looked and excuse my noobness, I’m struggling to see how I can trigger an action to say ‘set the Shelly level to the level of this other device’. This is my most important automation, the critical reason to act to moving to HA. Hoping for some hive mind help.

Thanks!

You can create an automation (using the gui) to trigger on a state change of the incoming device. The action of the automation can call light.turn_on on the target light, with the brightness being specified in a template that refers to the brightness of the incoming light, which is a state attribute.

You can use the states tool in the developer tools to figure out the attribute name, and the templates developer tool to test your template syntax.

I don’t use C-bus or Home Bridge, so the following is a very rough example:

alias:  Matched Brightness
description: ''
mode: single
trigger:
  - platform: state
    entity_id: light.cbus
    attribute: brightness
condition: []
action:
  - service: light.turn_on
    target:
      entity_id: light.shelly_dimmer
    data:
      brightness: "{{ trigger.to_state.state }}"

Thanks, really helpful and is helping my understanding of how it all fits together. I’ve worked out I needed to change the above (it has a mismatch error, I think because of the homekit2 device) which is a virtual device on the CBUS side which is presented to Homekit, and then through to HA.

Still not there yet, tho. Image below is of the cbus switch, and changing that on the cbus side works as an on, off, or a dimmer value, and that is flowing through nicely to HA.
The Shelly also is working from HA, and I can control and dim through HA.

The two devices work and are being reported correctly in HA, that piece is OK.

What I can’t still do is have the Shelly be triggered with the value of the incoming cbus value.
Here’s the code I’ve got to so far, which doesn’t error when creating in YAML, does anything stand out here as wrong?

In the device states page for the cbus device I see:
supported_color_modes:

    • brightness*
      friendly_name: Ensuite-Homekit-2
      supported_features: 1
alias: Test2
mode: single
sequence:
  - condition: state
    entity_id: light.ensuite_homekit_2
    attribute: supported_features          **<THIS may be wrong and the problem?**
    state: brightness                       **<and this may be wrong. How do I find the attributes on a device?**
  - service: light.turn_on
    target:
      entity_id: light.shower_light
    data:
      brightness: '{{ trigger.to_state.state }}'

You haven’t created an automation so far as I can see.

Ah ok I see. I’m trying this but refuses to save:

alias: Test2
mode: single
trigger:
  - platform: state
    entity_id: light.ensuite_homekit_2
sequence:
  - condition: state
    entity_id: light.ensuite_homekit_2
    attribute: supported_features
    state: brightness
  - service: light.turn_on
    target:
      entity_id: light.shower_light
    data:
      brightness: '{{ trigger.to_state.state }}'

Not sequence, action. Have you read any documentation? Understanding Automations - Home Assistant

1 Like

Show us a screen shot from the Developer Tools > States tool for light.ensuite_homekit_2 so that we can see how to extract the brightness data. (Make sure the light is on)

I have, but this is all very new, including YAML so getting all the parts in my head is a journey.

This is what I see with the switch on, @Didgeridrew

supported_color_modes:
  - brightness
color_mode: brightness
brightness: 255
friendly_name: Ensuite-Homekit-2
supported_features: 1

Late reply

I use this


alias: Match brightness CBUS to Hue with Scripts
trigger:
  - platform: mqtt
    topic: cbus/read/254/56/16/level
action:
  - service_template: |
      {% if trigger.payload|int == 0 %}                     
        script.light_off                                    
      {% else %}                                            
        script.light_on                                     
      {% endif %}                                           
    data_template:
      light: light.hue_office_desk
      brightness: "{{ trigger.payload }}"

I’ve been using this, where light.shellyrgbw2 is the friendly name of a cbus switch in HA

  - service: light.turn_on
    target:
      entity_id: light.shellyrgbw2
    data:
      brightness: "{{ state_attr('light.bathroom_shelly','brightness') |int(0) }}"
      rgb_color: [255, 255, 255]
  mode: single