Alexa - Set Light Bulb to ANY Colour

As you can’t set light colours via the emulated_hue component, I decided to go down the Custom Skill route.

Taking inspiration from the Working with Scenes section of the Alexa / Amazon Echo component page I created a skill that changes the colour of my RGB WiFi Bulbs running custom firmware, AiLight by @stelgenhof via Alexa. But this will work with any RGB light.

First follow the instructions under “Requirements” here to create a skill in the Amazon Developer Console.

Then add the following to your Skill.

Intent Schema

{
  "intents": [
    {
      "slots": [
        {
          "name": "Light",
          "type": "Lights"
        },
        {
          "name": "Colour",
          "type": "Colours"
        }
      ],
      "intent": "SetLightColour"
    }
  ]
}

Custom Slot Types

Slot 1: Colours:


For this I used all of the CSS3 color names as mentioned for the service data attribute color_name for light.turn_on

CSS3 Color Names

aliceblue
antiquewhite
aqua
aquamarine
azure
beige
bisque
black
blanchedalmond
blue
blueviolet
brown
burlywood
cadetblue
chartreuse
chocolate
coral
cornflowerblue
cornsilk
crimson
cyan
darkblue
darkcyan
darkgoldenrod
darkgray
darkgreen
darkgrey
darkkhaki
darkmagenta
darkolivegreen
darkorange
darkorchid
darkred
darksalmon
darkseagreen
darkslateblue
darkslategray
darkslategrey
darkturquoise
darkviolet
deeppink
deepskyblue
dimgray
dimgrey
dodgerblue
firebrick
floralwhite
forestgreen
fuchsia
gainsboro
ghostwhite
gold
goldenrod
gray
green
greenyellow
grey
honeydew
hotpink
indianred
indigo
ivory
khaki
lavender
lavenderblush
lawngreen
lemonchiffon
lightblue
lightcoral
lightcyan
lightgoldenrodyellow
lightgray
lightgreen
lightgrey
lightpink
lightsalmon
lightseagreen
lightskyblue
lightslategray
lightslategrey
lightsteelblue
lightyellow
lime
limegreen
linen
magenta
maroon
mediumaquamarine
mediumblue
mediumorchid
mediumpurple
mediumseagreen
mediumslateblue
mediumspringgreen
mediumturquoise
mediumvioletred
midnightblue
mintcream
mistyrose
moccasin
navajowhite
navy
oldlace
olive
olivedrab
orange
orangered
orchid
palegoldenrod
palegreen
paleturquoise
palevioletred
papayawhip
peachpuff
peru
pink
plum
powderblue
purple
red
rosybrown
royalblue
saddlebrown
salmon
sandybrown
seagreen
seashell
sienna
silver
skyblue
slateblue
slategray
slategrey
snow
springgreen
steelblue
tan
teal
thistle
tomato
turquoise
violet
wheat
white
whitesmoke
yellow
yellowgreen

Slot 2: Lights:
List the lights you want to control using their entity ID, excluding “light.” and any _ (.e.g. ‘light.hallway_lights’ becomes ‘hallway lights’)

You don’t actually need to add this, it will still work without it by just saying the name to Alexa, however this might make it more accurate + in the future hopefully we’ll be able to use Synonyms in Home Assistant for each slot name (doesn’t work at the moment)… more on this later…

Sample Utterances

SetLightColour Set {Light} to {Colour}

Home Assistant Config

Configuration.yaml

alexa:
intent_script: !include intent_script.yaml

intent_script.yaml

  SetLightColour:
    action:
      service: light.turn_on
      data_template:
        entity_id: light.{{ Light | replace(" ", "_") }}
        color_name: '{{ Colour | replace(" ", "_") }}'
    speech:
      type: plain
      text: >
         Light Set to '{{ Colour | replace(" ", "_") }}'

Now I can ask: “Alexa, ask Home Assistant to set big lamp to blue” or “Alexa, ask Home Assistant to set Hallway Lights to coral”… Alexa will then set the colour and return the speech: “Light set to (colour she heard)”

I’ll try any upload a video of this later.


Now for a bit of a caveat, because Alexa requires the entity ID of the device and not the friendly name it can cause some issues with the utterance sentence being fluid… for example I have a light in my bedroom, light.mike with a friendly name of “Mikes Lamp” - to set the colour of the lamp, I would need to ask “Alexa, ask Home Assistant to set Mike to Blue”… which doesn’t really roll of the tongue… now yes I could set “light.mike” to become “light.mikes_lamp” in Home Assistant…

But what would be much better is support for Synonyms of Slots in the Alexa / Intent_scripts component of Home Assistant…

Then using the Amazon Skill Builder Beta I could define different Synonyms for my custom Slot, Lights > Mike for example “Mike’s Lamp”, “Mike’s Light”, “Michael’s Lamp”.

I’ve submitted a feature request for support of Alexa Slot Synonyms, I’ve tested this today and it doesn’t work. I think this could be down to the component looking for:

this.event.request.intent.slots.SlotName.value and not this.event.request.intent.slots.SlotName.resolutions.resolutionsPerAuthority according to this forum post?

5 Likes

@badgerhome out of curiosity is your ISP Vigin Media?

@bachoo786 That’s a strange question, why do you ask?

And no it isn’t Virgin.

I am based in the UK and have the ISP virgin media which doesn’t allow me to forward my port from 443 to 80 or vice versa. Hence i cannot use your project.

And I thought you were based in the UK and had Virgin Media as your ISP.

Ah I see!

I’m in the UK but not on Virgin Media.

Can you use a different router instead of their Hub?

What router do you reckon would do the job? I had bought one from currys and it gave me issues getting my other devices to connect to the Internet.

I use an ASUS AC87U. Probably a bit over kill for most people’s needs but I run VPNs and all sorts on it.

Also flashed to use ASUSWRT which also has its own Home Assistant component for Presence

Ah right it’s too pricey for me I guess. Do you know any other routers which can do the trick?

I’m afraid not, might be worth checking out some Virgin Media forums?

Am i missing something? But AWS requires a secure SSL endpoint.

You would need to forward 443 > 8123 if you are running lets encrypt. You shouldn’t then have any issues, this is what i am doing.

That’s correct but on Virgin Media Superhub 2ac the router does not allow you to forward internal to external ports or vice versa.

Are you with Virgin Media?

Just thought I’d jump in as I’m on Virgin Media. I had no issues with the external > internal 443 > 8123 forwarding. I have the SuperHub 3 however (they’ll give you it for free if you ask), but bear in mind the admin interface can be incredibly slow if you switch to it. Often didn’t load for me, so I ended up getting a different router (similar to what @badgerhome has).

1 Like

Oh right I see did you just call them up? I never get to speak to the team in the UK.

And also what router did you go for?

Thanks.

I did yeah. I got the ASUS RT-AC3200. Definitely overkill for me, but it is great. Feel free to drop me a DM for any Virgin Media related questions.

2 Likes

Your code works for setting up a google home action, using that intent. Just need to change alexa: to apiai: .Only issue is the preview timer on action on google only lasting a short period.

Excellent! Good to know! Thinking of getting one to compare

I don’t like saying , “Alexa, ask home assistant” so I changed my skills to remove home assistant to something easier to say. This doesn’t take much more work except you need a new skill for each command you want.

Changing “ask home assistant” to “change” would allow

Alexa, change Mike’s Light to blue

I use

Alexa, tell me the location of john
Alexa, tell me the status of the kitchen light
Alexa, tell me the status of everything open

Yeah good idea, I changed mine recently to “house”.

Just been reading and apparently Haaska allows you to change RGB light in “smart home” so I could say “Alexa, set big lamp to blue” I will have to give it a go.

@badgerhome

hello matey, I tried alexa skills a little while back but couldnt get my endpoint to work, i always get this error:

“The remote endpoint could not be called, or the response it returned was invalid.”

Here is my endpoint URL:

https://XXXXXX.duckdns.org/api/alexa/SetLightColour?api_password=“password to log in to HA”

Have i done something wrong?

Hi mate I will check my config this evening and let you know.