[Automation, HowTo?] Update/synchronize custom device with only one Circadian attribute (RGB/Brightness)

Hi2UAll!

I need some help synchronizing/updating rgb-values (only) from a custom Mqtt-device to a LED device.

The source device is getting rgb-values from a custom MQTT-device to a Fibaro HC2 integrated LED-device.
Source: light.mqtt_circadian.attributes[“rgb_color”] <-- trigger in automation
Destination: light.woonkamer_eethoek_led_strip.attributes[“rgb_color”] <-- action in automation?

I only just want to update only this attribute, without using the turn_on service and/or changing other attributes.

Maybe an noob question, but can anyone show me how to do this?

I have problem to get the rgb value to my LED with Action. I tried a service call light.turn_on with data:
rgb_color: '{{state_attr("light.mqtt_circadian","rgb_color")}}'

I get an error in my log:
ERROR (MainThread) [homeassistant.components.automation] Error while executing automation automation.circadian_update. Invalid data for call_service at pos 2: None for dictionary value @ data['rgb_color']

The output value of the ‘{{state_attr(“light.mqtt_circadian”,“rgb_color”)}}’ is (255, 159, 70)`

I don’t know where the ( comes from, could this be the problem?

Found a solution by using Node-Red and MQTT:

I guess there is a far easier solution, but it works, so good enough for me… :wink:

Are you able to export the flow ?
I’m pulling my hair out trying to make my lights turn on at the circadian temp and fade up, rather than fade up to the last color and then change to the correct color…

I can give a small summary what I did, maybe it will help you to achieve your goal.

1 - I made a mqtt virtual light device using Node-Red:
image

  • The delete-inject-node is an string with no content (empty).
  • The config-function node contains:
var logTimeStamp = global.get('logTimeStamp')||"No Timestamp";
var _topic = "homeassistant/light/circadian";
var _qos = 2;
var _retain = true;
var _payload = {
    "name": "Mqtt Circadian",
    "unique_id": "mqtt_circadian",
    "command_topic": _topic + "/set",
    "brightness_command_topic": _topic + "/brightness",
    "rgb_command_topic": _topic + "/rgb_color",
    "device": {
        "name": "Mqtt Circadian",
        "manufacturer": "MQTT Hass.io",
        "model": "Custom",
        "identifiers": ["Mqtt Circadian"],
        "sw_version": "20191219"
        }
    };
if (msg.payload === '' ){
     node.status({fill:"red",shape:"dot",text: logTimeStamp + " " + _topic});
     _topic = _topic + "/config";
     _qos = 0;
     _retain = false;
     _payload = '';
    } else {
     node.status({fill:"green",shape:"dot",text: logTimeStamp + " " + _topic});
     _topic = _topic + "/config";
    }    
var message = {
    topic: _topic,
    qos: _qos,
    retain: _retain,
    payload: _payload
};
return message;

note: the global “logTimeStamp” is my custom global variable to show the activated timestamp with clock-symbol in front.

2 - Configured Circadian to use this device in the HA yaml files:
added in configuration.yaml:

# 20191219 Circadian Lighting
# https://github.com/claytonjn/hass-circadian_lighting
# https://community.home-assistant.io/t/circadian-lighting-custom-component
circadian_lighting:
  #interval: 60
  min_colortemp: 1500
  max_colortemp: 4500

Added in switch.yaml:

# 20191219 Circadian Lighting
# https://github.com/claytonjn/hass-circadian_lighting
# https://community.home-assistant.io/t/circadian-lighting-custom-component
  - platform: circadian_lighting
    min_brightness: 25
    lights_rgb:
      - light.mqtt_circadian

Now you have a virtual light device (light.mqtt_circadian) you can extract values from.

3 - Then I made a Node-Red flow to get the values the way I want:
image

[{"id":"a54920fd.059e78","type":"debug","z":"c1caafea.2479e8","name":"= on & rgb","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","x":650,"y":200,"wires":[]},{"id":"f8dacc2.21831b","type":"server-state-changed","z":"c1caafea.2479e8","name":"mqtt_circadian (on)","server":"2b4c77a9.ef4658","version":1,"exposeToHomeAssistant":false,"haConfig":[{"property":"name","value":""},{"property":"icon","value":""}],"entityidfilter":"light.mqtt_circadian","entityidfiltertype":"substring","outputinitially":false,"state_type":"str","haltifstate":"on","halt_if_type":"str","halt_if_compare":"is","outputs":2,"output_only_on_state_change":false,"x":130,"y":120,"wires":[["138f337b.088965","1cee51b5.ff36ae","94eff5ea.4a4c28"],[]]},{"id":"9c529ec5.e94a68","type":"comment","z":"c1caafea.2479e8","name":"Circadian Light control","info":"","x":140,"y":40,"wires":[]},{"id":"29a1da35.34e5f6","type":"comment","z":"c1caafea.2479e8","name":"Get Circadian values on change","info":"","x":230,"y":80,"wires":[]},{"id":"138f337b.088965","type":"debug","z":"c1caafea.2479e8","name":"= on","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","x":670,"y":120,"wires":[]},{"id":"c8a7bc2e.ed474","type":"switch","z":"c1caafea.2479e8","name":"not null","property":"payload","propertyType":"msg","rules":[{"t":"nnull"}],"checkall":"true","repair":false,"outputs":1,"x":460,"y":360,"wires":[["c18d0ad7.2d2c98","39b58418.57e244"]]},{"id":"c18d0ad7.2d2c98","type":"debug","z":"c1caafea.2479e8","name":"= on & brightness","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","x":630,"y":320,"wires":[]},{"id":"1cee51b5.ff36ae","type":"rbe","z":"c1caafea.2479e8","name":"on change","func":"rbe","gap":"","start":"","inout":"out","property":"data.new_state.attributes.rgb_color","x":130,"y":240,"wires":[["acc025c7.578b7"]]},{"id":"94eff5ea.4a4c28","type":"rbe","z":"c1caafea.2479e8","name":"on change","func":"rbe","gap":"","start":"","inout":"out","property":"data.new_state.attributes.brightness","x":130,"y":360,"wires":[["1fa91aa6.0c1ad5"]]},{"id":"acc025c7.578b7","type":"change","z":"c1caafea.2479e8","name":"Only RGB","rules":[{"t":"set","p":"payload","pt":"msg","to":"data.new_state.attributes.rgb_color","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":280,"y":240,"wires":[["15a6bb4f.90eb7d"]]},{"id":"1fa91aa6.0c1ad5","type":"change","z":"c1caafea.2479e8","name":"Only Brighness","rules":[{"t":"set","p":"payload","pt":"msg","to":"data.new_state.attributes.brightness","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":300,"y":360,"wires":[["c8a7bc2e.ed474"]]},{"id":"15a6bb4f.90eb7d","type":"switch","z":"c1caafea.2479e8","name":"not null","property":"payload","propertyType":"msg","rules":[{"t":"nnull"}],"checkall":"true","repair":false,"outputs":1,"x":460,"y":240,"wires":[["a54920fd.059e78","4dc2f54f.04599c"]]},{"id":"4dc2f54f.04599c","type":"link out","z":"c1caafea.2479e8","name":"lightContol - carcadianRGB","links":["e5aab1da.47c5e8","1f73084e.291218","8cf87d51.f3145"],"x":595,"y":240,"wires":[]},{"id":"39b58418.57e244","type":"link out","z":"c1caafea.2479e8","name":"lightContol - carcadianBrightness","links":["6e8ef7da.63df1","d15b5ae1.4ac448","f2cf2119.21b498","ebd785f0.9ded38","ee88905e.b8682"],"x":595,"y":360,"wires":[]},{"id":"392fb5e1.4908d2","type":"comment","z":"c1caafea.2479e8","name":"Set Circadian values to Globals","info":"","x":230,"y":420,"wires":[]},{"id":"e5aab1da.47c5e8","type":"link in","z":"c1caafea.2479e8","name":"lightControl - to_global.circadianRGB","links":["4dc2f54f.04599c"],"x":115,"y":460,"wires":[["557ec9c3.feddc"]]},{"id":"557ec9c3.feddc","type":"change","z":"c1caafea.2479e8","name":"RGB to global.circadianRGB","rules":[{"t":"set","p":"circadianRGB","pt":"global","to":"payload","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":320,"y":460,"wires":[[]]},{"id":"6e8ef7da.63df1","type":"link in","z":"c1caafea.2479e8","name":"lightControl - to_global.circadianBrightness","links":["39b58418.57e244"],"x":115,"y":500,"wires":[["32235da8.90f642"]]},{"id":"32235da8.90f642","type":"change","z":"c1caafea.2479e8","name":"brightness to global.circadianBrighness","rules":[{"t":"set","p":"circadianBrighness","pt":"global","to":"payload","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":360,"y":500,"wires":[[]]},{"id":"2b4c77a9.ef4658","type":"server","z":"","name":"hassio.myowndomain","legacy":false,"hassio":true,"rejectUnauthorizedCerts":true,"ha_boolean":"y|yes|true|on|home|open","connectionDelay":true}]

P.S. I didn’t use the Brightness- and RGB-level values Node Red global variables, this is for future purpose.

4 I Used the extracted values to control my light(s):
image
Adjust RGB call service node data:

{"rgb_color": [{{payload}}]}

note: be aware of the square-brackets!

Adjust Brightness call service node data:
{"brightness": {{payload}}}
Note: wait for the values to be updated for the first time, in my example this is 5 minutes!

Edit: Example of Node-Red UI output I used to monitor:

I hope this will help you out to get your config working!

1 Like

Wowzer thats a lot more complex than I thought it would be !
Thanks for the detailed write up, I was pulling the rgb, splitting it so I could then round it to zero decimals, then joining it and then trying to pass it to a light.
Just kept getting either too much data or blank data for the rgb value.

I’ll have a proper look tomorrow.

Thanks again.

1 Like

One thing I had to discover that the RGB-values is an array which needs the square-brackets for handling, just be aware of that.

Because I’m not an expert, this is my way to achieve it. There are probably far more other (easier) solutions, but I have not the knowledge for that, so I have to split it in basic steps, which is easier to debug and understand (for me).
EDIT: In essential
step 1 - make a HA virtual light device
step 2 - configure HA to make Circadian use of this virtual light
step 3 - extract values from virtual light
step 4 - use the extracted values to control other HA devices

I lot of thinks I use this try/debug/discover/learn method… :wink:

So if you find your solution, please share!

1 Like

Yea, the array list thingy has been a headache for me.
I post if I crack it

Thanks once again

1 Like

You’re very welcome!