Pull lights from Alexa to Node Red

So i have some wifi light bulbs that I can control easily with Google Home or Alexa, but not so easily with homeassistant. I’ve tinkered enough in Node Red to be intimidated.

Has anyone successfully pulled a light from Alexa or Google Home into Node Red and controlled it with HA? Ideally I’d want to be able to control brightness and colors.

Any help is most appreciated.

I’ve controlled an Alexa outlet with the custom component Alexa Media Player. I had to create routines in Alexa, then Alexa Media Player can be used to trigger the routine i setup in the Alexa app. I only needed two routines though, one for on, and one for off. For a bulb with color and brightness, you would need seperate routines for each color or brightness you want to set it to though, so it’s not a great approach. You also can’t feed status of the bulb to Home Assistant, so home assistant would have no idea what the bulbs current state is, ie no idea if it’s on or off.

What is the model of the bulb? There could be a better approach for control beside using Alexa.

I just checked and there are options to increase or decrease brightness by 25% in a routine, so that could make that work for brightness. Color would be a pain still though

Here’s a sample node red call service node to trigger an Alexa routine using Alexa Media player - GitHub - custom-components/alexa_media_player: This is a custom component to allow control of Amazon Alexa devices in Home Assistant using the unofficial Alexa API.

[{"id":"e039a4d644b88461","type":"api-call-service","z":"69a413c2.3f382c","name":"Stop Music","server":"ae531ce.a39906","version":5,"debugenabled":false,"domain":"media_player","service":"play_media","areaId":[],"deviceId":[],"entityId":["media_player.bedroom"],"data":"{\"entity_id\":\"media_player.downstairs\",\"media_content_id\":\"stop all music\",\"media_content_type\":\"routine\"}","dataType":"json","mergeContext":"","mustacheAltTags":false,"outputProperties":[],"queue":"none","x":410,"y":80,"wires":[[]]},{"id":"ae531ce.a39906","type":"server","name":"Home Assistant","version":4,"addon":false,"rejectUnauthorizedCerts":true,"ha_boolean":"y|yes|true|on|home|open","connectionDelay":true,"cacheJson":true,"heartbeat":false,"heartbeatInterval":"30","areaSelector":"friendlyName","deviceSelector":"friendlyName","entitySelector":"friendlyName","statusSeparator":"at: ","statusYear":"hidden","statusMonth":"short","statusDay":"numeric","statusHourCycle":"h23","statusTimeFormat":"h:m"}]

This is all you need. 100% NR, more potent, more stable and more versatile than Alexa Media Player

You can set variable color/brightnes/whatever without needing to create a routine for each.

1 Like

Interesting, thanks guys.

So ultimately I’d love to pull all of this into a light entity/device so it behaves like a normal light in HA. Not sure how to code that in Node Red. Anyone done it?

Yup. Create a template light in HA and fire an event for each brightness and color calls.

Then pass that info to and applestrudle node.

Very interesting, i’ll see if i can figure this out. Thanks alot man!

Any way you could elaborate a little more?

Not sure how to fire an event or which node red nodes to tie together in what order to make this work.

ok, I don’t have this set up so I’ll give you something so you get the idea.

YAML example for set_color, disregard the other stuff:

      mesita:
        friendly_name: Mesita
        turn_on:
        - service: nodered.trigger
          data:
            skip_condition: true
            output_path: true
            entity_id: switch.nodered_mesita_from_ha_to_nr
        turn_off:
        - service: nodered.trigger
          data:
            skip_condition: true
            output_path: false
            entity_id: switch.nodered_mesita_from_ha_to_nr
        set_color:
          - event: mesita_changed
            event_data:
              h: "{{h}}"
              s: "{{s}}"
        color_template: "({{states('sensor.hue_mesita') | int}}, {{states('sensor.saturation_mesita') | int}})"

Then in NR

[{"id":"aff607db67440919","type":"server-events","z":"9d6232bd.2dfe7","name":"","server":"9405c3fe.d0a6c","version":2,"eventType":"mesita_changed","exposeToHomeAssistant":false,"eventData":"","haConfig":[{"property":"name","value":""},{"property":"icon","value":""}],"waitForRunning":true,"outputProperties":[{"property":"payload","propertyType":"msg","value":"","valueType":"eventData"},{"property":"topic","propertyType":"msg","value":"$outputData(\"eventData\").event_type","valueType":"jsonata"}],"event_type":"","x":330,"y":520,"wires":[["ebf63d2bd8a8bbeb"]]},{"id":"1856e4583239ab5c","type":"color-convert","z":"9d6232bd.2dfe7","input":"hsv","output":"hex","outputType":"string","scaleInput":false,"x":710,"y":520,"wires":[["b5cbf8ef7abbadbb"]]},{"id":"ebf63d2bd8a8bbeb","type":"change","z":"9d6232bd.2dfe7","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"[payload.event.h,payload.event.s,100]","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":540,"y":520,"wires":[["1856e4583239ab5c"]]},{"id":"b5cbf8ef7abbadbb","type":"alexa-remote-routine","z":"9d6232bd.2dfe7","name":"","account":"7c02d978.c2de98","routineNode":{"type":"node","payload":{"type":"serial","children":[{"type":"smarthome","payload":{"entity":"069402ac-566f-4694-853e-694ce6accdd4","action":"setColor","value":{"type":"msg","value":"payload"}}}]}},"x":920,"y":520,"wires":[[]]},{"id":"9405c3fe.d0a6c","type":"server","name":"Home Assistant","version":5,"addon":true,"rejectUnauthorizedCerts":true,"ha_boolean":"y|yes|true|on|home|open","connectionDelay":true,"cacheJson":true,"heartbeat":false,"heartbeatInterval":30,"areaSelector":"friendlyName","deviceSelector":"friendlyName","entitySelector":"friendlyName","statusSeparator":"at: ","statusYear":"hidden","statusMonth":"short","statusDay":"numeric","statusHourCycle":"h23","statusTimeFormat":"h:m","enableGlobalContextStore":true},{"id":"7c02d978.c2de98","type":"alexa-remote-account","name":"","authMethod":"proxy","proxyOwnIp":"192.168.1.29","proxyPort":"1234","cookieFile":"/config/.storage/authentication","refreshInterval":"3","alexaServiceHost":"alexa.amazon.es","amazonPage":"amazon.es","acceptLanguage":"es-ES","onKeywordInLanguage":"on","userAgent":"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/15.5 Safari/605.1.15","useWsMqtt":"on","autoInit":"on"}]

That grey node is color-convert, you’ll need it to convert from Hue,Saturation to HEX: node-red-contrib-color-convert

You’re awesome, thank you!