Jump to content

Welcome to Smart Home Forum by FIBARO

Dear Guest,

 

as you can notice parts of Smart Home Forum by FIBARO is not available for you. You have to register in order to view all content and post in our community. Don't worry! Registration is a simple free process that requires minimal information for you to sign up. Become a part of of Smart Home Forum by FIBARO by creating an account.

 

As a member you can:

  •     Start new topics and reply to others
  •     Follow topics and users to get email updates
  •     Get your own profile page and make new friends
  •     Send personal messages
  •     ... and learn a lot about our system!

 

Regards,

Smart Home Forum by FIBARO Team


HueConnector - Hue v2 API


jgab

Recommended Posts

I have started to code a Hue QA that uses the new V2 api. It's still early beta... (v0.11)

It's available via the QAUpdater QA.

The QA is a standalone QA that keeps an updated state of the Hue resources and accept commands to change them - like turning on/off lights.

It only provides an API (fibaro.call, fibaro.getValue) and no QuickAppChild devices (the latter can be built relatively easy built using HueConnector...)

 

To use the QA you create a your own client QA that calls the HueConnector QA.

Example client:

Please login or register to see this code.

This example uses 3 Hue devices, a motion/lux/temp sensor, a light (Tim), and a switch.

 

The QA supports devices, rooms, zones and scenes.

 

We can send command to the Hue light with fibaro.call. Note that the id is the Hue uid and not a device number.

When a device changes state there is a callback to QuickApp:hueEvent with the uid and the event.

 

There is a deviceMap (more about that later) accessible with self.hue.getRsrc("deviceMap") that maps Hue ids to the various properties of the device/resource.

In particular, name and room.

This allows us to build a map from our own IDs to hue ids as they may be easier to deal with.

In the example above we map the light "3ab27084-d02f-44b9-bd56-70ea41163cb6" that has the name "Tim" and room "Guest room" to

"Guest_room_Tim"="3ab27084-d02f-44b9-bd56-70ea41163cb6"

in the self.hue.deviceMap[] table. 

That table is used by fibaro.call so if the id is in the  self.hue.deviceMap table it will use that mapping.

This allows us to call

Please login or register to see this code.

in our example.

but it also works with fibaro.call("3ab27084-d02f-44b9-bd56-70ea41163cb6","setColor","green")

 

Only lights, rooms, zones and scenes can take commands:

  • fibaro.call(uid,"turnOn"[,transition])                         --  transition in ms. 
  • fibaro.call(uid,"turnOff"[,transition])                        --  transition in ms. 
  • fibaro.call(uid,"toggle"[,transition])                          --  transition in ms. 
  • fibaro.call(uid,"setDim",value[,transition])).              -- value 0-100, transition in ms. 
  • fibaro.call(uid,"setTemperature",value[,transition])  -- value in mirek
  • fibaro.call(uid,"setColor",<string> | {x=x, y=y} | {r=r,g=g,b=b}[,transition]) -- color string, ex "green" or x,y float values. (RGB support tbd)
  • fibaro.call(uid,"recall"[,transition])                             -- Recall scene for scene with uid.
  • fibaro.call(uid,"sendRaw",<table>)                            -- POST raw command to Hue device with uid

 

Sensor properties

  • motion           -- true/false
  • temperature -- temperature
  • light              -- lux
  • status           -- connected/reachable
  • power_state -- battery

Buttons/switches properties

  • button           -- button pressed
  • status            -- connected/reachable
  • power_state  -- battery

Lights properties

  • on                             -- true/false
  • dimming                   -- 0-100
  • color_temperature  -- mirek
  • color                         -- x,y
  • status                       -- connected/reachable

 

To use this there is a small Hue client library that needs to be included in the QA

Please login or register to see this spoiler.

On top of this it would be relatively easy to create ex. childDevices for each device etc.

 

So, there is some setup that needs be done for the HueConnector QA too.

There are quickApp variables with "Hue_IP" and "Hue_User". The latter is the api key you get from the hub.

 

You can dump the current devices, rooms, zones and scenes (the resources we can work with)

When I log my resources looks like

Please login or register to see this code.

 

That table is the one used when creating a custom mapping between names and Hue uids

 

There will be improvements in the coming week and also hoping the V2 API will mature a bit more.

There are some speed improvements that I know about that will improve the QA significantly...

Edited by jgab
  • Like 6
  • Thanks 2
Link to comment
Share on other sites

4 hours ago, jgab said:

I have started to code a Hue QA that uses the new V2 api. It's still early beta...

It's available via the QAUpdater QA.

The QA is a standalone QA that keeps an updated state of the Hue resources and accept commands to change them - like turning on/off lights.

It only provides an API (fibaro.call, fibaro.getValue) and no QuickAppChild devices (the latter can be built relatively easy built using HueConnector...)

 

To use the QA you create a your own client QA that calls the HueConnector QA.

Example client:

Please login or register to see this code.

This example uses 3 Hue devices, a motion/lux/temp sensor, a light (Tim), and a switch.

We can send command to the Hue light with fibaro.call. Note that the id is the Hue uid and not a device number.

When a device changes state there is a callback to QuickApp:hueEvent with the uid and the event.

 

There is a deviceMap (more about that later) accessible with self.hue.getRsrc("deviceMap") that maps Hue ids to the various properties of the device/resource.

In particular, name and room.

This allows us to build a map from our own IDs to hue ids as they may be easier to deal with.

In the example above we map the light "3ab27084-d02f-44b9-bd56-70ea41163cb6" that has the name "Tim" and room "Guest room" to

"Guest_room_Tim"="3ab27084-d02f-44b9-bd56-70ea41163cb6"

in the self.hue.deviceMap[] table. 

That table is used by fibaro.call so if the id is in the  self.hue.deviceMap table it will use that mapping.

This allows us to call

Please login or register to see this code.

in our example.

but it also works with fibaro.call("3ab27084-d02f-44b9-bd56-70ea41163cb6","setColor","green")

 

Only lights can take commands:

  • fibaro.call(uid,"turnOn")
  • fibaro.call(uid,"turnOff")
  • fibaro.call(uid,"setDim",value[,delay])).   -- delay in ms. 
  • fibaro.call(uid,"setTemperature",value)
  • fibaro.call(uid,"setColor",<string> | x,y)

 

Sensor properties

  • motion           -- true/false
  • temperature -- temperature
  • light              -- lux
  • status           -- connected/reachable
  • power_state -- battery

Buttons/switches properties

  • button           -- button pressed
  • status            -- connected/reachable
  • power_state  -- battery

Lights properties

  • on                             -- true/false
  • dimming                   -- 0-100
  • color_temperature  -- mirek
  • color                         -- x,y
  • status                       -- connected/reachable

 

To use this there is a small Hue client library that needs to be included in the QA

Please login or register to see this spoiler.

Great suff @jgab  Thank you for your work

 i just need the integration in EV4 -  do i need the "your own client QA" ? 

Please login or register to see this code.

 

- i have startet testing :-) 

Please login or register to see this code.

 

Edited by ChristianSogaard
P
Link to comment
Share on other sites

Jan, I can't test but do I miss transition time, or will this be arranged on another way?

Link to comment
Share on other sites

  • Topic Author
  • 2 hours ago, ChristianSogaard said:

    Great suff @jgab  Thank you for your work

     i just need the integration in EV4 -  do i need the "your own client QA" ? 

    The integration with ER4 will come - just need time to make sure that the basics works first.

    2 hours ago, Sjakie said:

    Jan, I can't test but do I miss transition time, or will this be arranged on another way?

    There is a transition time for setDim. (delay). I may generalise it to setColor and setTemperature too - depends on how the V2 api evolves...

    Is it something else you need?

    Edited by jgab
    • Thanks 1
    Link to comment
    Share on other sites

    Jan with great pleasure I use:

    Please login or register to see this code.

    and I think I can do that in your new HUE QA

    Thanks for your effort and easy to use rules.

    Link to comment
    Share on other sites

  • Topic Author
  • The color strings that are accepted by setColor are

    Please login or register to see this code.

    Ex.

    Please login or register to see this code.

    which is the same as

    Please login or register to see this code.

     

    I believe the table is from the HASS Hue plugin but I have forgot the actual link.

     

    9 minutes ago, Sjakie said:

    Jan with great pleasure I use:

    Please login or register to see this code.

    and I think I can do that in your new HUE QA

    Thanks for your effort and easy to use rules.

     

    Well, Hue and Sat is kind of gone with v2 as all colors are expressed in x,y.

    I have some conversion between rgb and hue/sat and xy but it's far from perfect. We need rgb as it's used by the favourite colors in the HC3 UI so that I will add.

    You will be able to send raw hue commands in V2 too, but the format is a bit different.

    Most commands can take a transition time so I believe that will work.

    Edited by jgab
    • Thanks 1
    Link to comment
    Share on other sites

    Jan, this I use as basic:

    Please login or register to see this code.

     

    Edited by Sjakie
    typo
    Link to comment
    Share on other sites

  • Topic Author
  • 1 minute ago, Sjakie said:

    Jan, this I use as basic:

    Please login or register to see this code.

     

    You need to find some xy value that work as "a tad blue", or some colorstring that is close enough.

    If you find your values I can add "a_tad_blue" etc to the color table :-)

    Link to comment
    Share on other sites

    In hue essentials you can get the xy and hex for the colors.

     

     

     

     

    Please login or register to see this attachment.

     

     

    Also this might help, all x y for populair scene's

     

    Quote
    • Hue Ambiance lights

      • Relax

        • brightness: 145

        • color_temp: 447

    • o Read

    • § brightness: 255

    • § color_temp: 346

    • o Concentrate

    • § brightness: 255

    • § color_temp: 233

    • o Energize

    • § brightness: 255

    • § color_temp: 156

    • o Savanna sunset

    • § brightness: 145

    • § color_temp: 447

    • o Tropical twilight

    • § brightness: 187

    • § color_temp: 322

    • o Artic auroa

    • § brightness: 150

    • § color_temp: 153

    • o Spring blossom

    • o Bright

    • o Dimmed

    • o Nightlight

    • · Hue white lights

    • o Bright

    • § Brightness: 255

    • o Dimmed

    • § brightness: 77

    • o Nightlight

    • § brightness: 1

    • · Hue color lights

    • o Savanna sunset

    • § brightness: 200

    • § hs_color:

    • § 14.717

    • § 83.137

    • § rgb_color:

    • § 255

    • § 95

    • § 43

    • § xy_color:

    • § 0.635

    • § 0.335

    • o Tropical Twilight

    • § brightness: 123

    • § hs_color:

    • · 263.182

    • · 34.51

    • § rgb_color:

    • · 200

    • · 166

    • · 255

    • § xy_color:

    • · 0.29

    • · 0.224

    • o Artic Aurora

    • § brightness: 138

    • § hs_color:

    • · 201.308

    • · 83.922

    • § rgb_color:

    • · 40

    • · 179

    • · 255

    • § xy_color:

    • · 0.152

    • · 0.219

    • o Spring Blossom

    • § brightness: 215

    • § hs_color:

    • · 339.718

    • · 27.843

    • § rgb_color:

    • · 255

    • · 184

    • · 208

    • § xy_color:

    • · 0.394

    • · 0.298

    • o Relax

    • § brightness: 145

    • § hs_color:

    • · 36.568

    • · 66.275

    • § rgb_color:

    • · 255

    • · 188

    • · 85

    • § xy_color:

    • · 0.502

    • · 0.414

    • o Read

    • § brightness: 255

    • § hs_color:

    • · 38.88

    • · 49.02

    • § rgb_color:

    • · 255

    • · 210

    • · 129

    • § xy_color:

    • · 0.447

    • · 0.406

    • o Concentrate

    • § brightness: 255

    • § hs_color:

    • · 45

    • · 21.961

    • § rgb_color:

    • · 255

    • · 240

    • · 198

    • § xy_color:

    • · 0.37

    • · 0.372

    • o Energize

    • § brightness: 255

    • § hs_color:

    • · 173.333

    • · 3.529

    • § rgb_color:

    • · 246

    • · 255

    • · 254

    • § xy_color:

    • · 0.314

    • · 0.331

    • o Bright

    • § brightness: 255

    • § hs_color:

    • · 38.667

    • · 52.941

    • § rgb_color:

    • · 255

    • · 207

    • · 120

    • § xy_color:

    • · 0.457

    • · 0.41

    • o Dimmed

    • § brightness: 77

    • § hs_color:

    • · 38.222

    • · 52.941

    • § rgb_color:

    • · 255

    • · 205

    • · 120

    • § xy_color:

    • · 0.459

    • · 0.408

    • o Nightlight

    • § brightness: 1

    • § hs_color:

    • · 33.767

    • · 84.314

    • § rgb_color:

    • · 255

    • · 160

    • · 39

    • § xy_color:

    • · 0.561

    • · 0.404

    • · Bloom

    • o Savana sunset

    • § brightness: 200

    • § hs_color:

    • · 28.605

    • · 67.451

    • § rgb_color:

    • · 255

    • · 165

    • · 82

    • § xy_color:

    • · 0.531

    • · 0.389

    • o Tropical twilight

    • § brightness: 123

    • § hs_color:

    • · 263.864

    • · 34.51

    • § rgb_color:

    • · 202

    • · 166

    • · 255

    • § xy_color:

    • · 0.292

    • · 0.224

    • o Artic aurora

    • § brightness: 138

    • § hs_color:

    • · 202.871

    • · 79.216

    • § rgb_color:

    • · 52

    • · 178

    • · 255

    • § xy_color:

    • · 0.156

    • · 0.218

    • o Spring blossom

    • § brightness: 215

    • § hs_color:

    • · 338.333

    • · 28.235

    • § rgb_color:

    • · 255

    • · 183

    • · 209

    • § xy_color:

    • · 0.394

    • · 0.295

    • o Bright

    • § brightness: 255

    • § hs_color:

    • · 38.824

    • · 53.333

    • § rgb_color:

    • · 255

    • · 207

    • · 119

    • § xy_color:

    • · 0.458

    • · 0.411

    • o Dimmed

    • § brightness: 77

    • § hs_color:

    • · 38.978

    • · 53.725

    • § rgb_color:

    • · 255

    • · 207

    • · 118

    • § xy_color:

    • · 0.458

    • · 0.412

    • o Nightlight

    • § brightness: 1

    • § hs_color:

    • · 36.053

    • · 89.412

    • § rgb_color:

    • · 255

    • · 164

    • · 26

    • § xy_color:

    • · 0.559

    • · 0.412

    • · LED Strips (I have 2)

    • o Savana sunset

    • § Strip 1

    • · brightness: 200

    • · hs_color:

    • o 14.93

    • o 83.529

    • · rgb_color:

    • o 255

    • o 95

    • o 42

    • · xy_color:

    • o 0.636

    • o 0.335

    • § Strip 2

    • · brightness: 200

    • · hs_color:

    • o 18.387

    • o 72.941

    • · rgb_color:

    • o 255

    • o 126

    • o 69

    • · xy_color:

    • o 0.586

    • o 0.353

    • o Tropical twilight

    • § Strip 1

    • · brightness: 123

    • · hs_color:

    • o 321.509

    • o 20.784

    • · rgb_color:

    • o 255

    • o 202

    • o 236

    • · xy_color:

    • o 0.359

    • o 0.29

    • § Strip 2

    • · brightness: 123

    • · hs_color:

    • o 27.797

    • o 69.412

    • · rgb_color:

    • o 255

    • o 160

    • o 77

    • · xy_color:

    • o 0.541

    • o 0.386

    • o Artic aurora

    • § Strip 1

    • · brightness: 138

    • · hs_color:

    • o 235

    • o 75.294

    • · rgb_color:

    • o 63

    • o 79

    • o 255

    • · xy_color:

    • o 0.158

    • o 0.087

    • § Strip 2

    • · brightness: 134

    • · hs_color:

    • o 144.564

    • o 58.431

    • · rgb_color:

    • o 106

    • o 255

    • o 167

    • · xy_color:

    • o 0.209

    • o 0.487

    • o Spring blossom

    • § Strip 1

    • · brightness: 215

    • · hs_color:

    • o 339.718

    • o 27.843

    • · rgb_color:

    • o 255

    • o 184

    • o 208

    • · xy_color:

    • o 0.394

    • o 0.298

    • § Strip 2

    • · brightness: 215

    • · hs_color:

    • o 339.6

    • o 58.824

    • · rgb_color:

    • o 255

    • o 104

    • o 155

    • · xy_color:

    • o 0.505

    • o 0.268

    • o Relax

    • § Strip 1

    • · brightness: 145

    • · hs_color:

    • o 36.568

    • o 66.275

    • · rgb_color:

    • o 255

    • o 188

    • o 85

    • · xy_color:

    • o 0.502

    • o 0.414

    • § Strip 2

    • o Read

    • § Strip 1

    • · brightness: 255

    • · hs_color:

    • o 38.88

    • o 49.02

    • · rgb_color:

    • o 255

    • o 210

    • o 129

    • · xy_color:

    • o 0.447

    • o 0.406

    • § Strip 2

    • o Concentrate

    • § Strip 1

    • · brightness: 255

    • · hs_color:

    • o 45

    • o 21.961

    • · rgb_color:

    • o 255

    • o 240

    • o 198

    • · xy_color:

    • o 0.37

    • o 0.372

    • § Strip 2

    • o Energize

    • § Strip 1

    • · brightness: 255

    • · hs_color:

    • o 173.333

    • o 3.529

    • · rgb_color:

    • o 246

    • o 255

    • o 254

    • · xy_color:

    • o 0.314

    • o 0.331

    • § Strip 2

    • o Bright

    • § Strip 1

    • · brightness: 255

    • · hs_color:

    • o 38.222

    • o 52.941

    • · rgb_color:

    • o 255

    • o 205

    • o 120

    • · xy_color:

    • o 0.459

    • o 0.408

    • § Strip 2

    • o Dimmed

    • § Strip 1

    • · brightness: 77

    • · hs_color:

    • o 38.222

    • o 52.941

    • · rgb_color:

    • o 255

    • o 205

    • o 120

    • · xy_color:

    • o 0.459

    • o 0.408

    • § Strip 2

    • o Nightlight

    • § Strip 1

    • · brightness: 25

    • · hs_color:

    • o 33.767

    • o 84.314

    • · rgb_color:

    • o 255

    • o 160

    • o 39

    • · xy_color:

    • o 0.561

    • o 0.404

    • § Strip 2

     

     

    Edited by ppeterr
    • Like 3
    Link to comment
    Share on other sites

    Jan will there be also integration in ER or can we use in several QA's :

     

    Please login or register to see this code.

    is 0)  transition time?

     

    or can we change white by x,y 

    Please login or register to see this code.

    If not can you please add the main HUE colors?

    Please login or register to see this code.

     

    Edited by Sjakie
    request for color names
    Link to comment
    Share on other sites

  • Topic Author
  • Updated to 0.11 and some changes in the original post. Simpler handling of the HueDeviceTable and some more functions.

    Link to comment
    Share on other sites

    4 hours ago, jgab said:

    Updated to 0.11 and some changes in the original post. Simpler handling of the HueDeviceTable and some more functions.

    Thank you :-) i will update

    Manually or will you put 0.11 in the QA updater later ?

     

    Link to comment
    Share on other sites

  • Topic Author
  • I pushed a new version of HueConnector v0.12. It's mainly bug fixes.

     

    There is also a new QA, HueSensors, that uses the HueConnector and creates child devices for all the Hue sensors and buttons. These can then easily be used from HC3 scenes etc.

    (No support for lights!)

    Please login or register to see this attachment.

    It can in principle handle everything with buttons, light sensors, temperature sensors and motion sensors.

    I will add support for the Hue wall plug (even if it's technically not a sensor) and the Hue Tap with the rotary dial in the coming days.

    'HueSensors' is also available via QAUpdater.

     

    It's interesting how "simple" and straightforward it becomes to creates devices using the HueConnector. Here is the code for HueSensors (it also uses my QuickerChild and HueClient library)

    Please login or register to see this code.

     

    Edited by jgab
    • Like 3
    • Thanks 1
    Link to comment
    Share on other sites

    13 hours ago, jgab said:

    I pushed a new version of HueConnector v0.12. It's mainly bug fixes.

     

    There is also a new QA, HueSensors, that uses the HueConnector and creates child devices for all the Hue sensors and buttons. These can then easily be used from HC3 scenes etc.

    (No support for lights!)

    Please login or register to see this attachment.

    It can in principle handle everything with buttons, light sensors, temperature sensors and motion sensors.

    I will add support for the Hue wall plug (even if it's technically not a sensor) and the Hue Tap with the rotary dial in the coming days.

    'HueSensors' is also available via QAUpdater.

     

    It's interesting how "simple" and straightforward it becomes to creates devices using the HueConnector. Here is the code for HueSensors (it also uses my QuickerChild and HueClient library)

    Please login or register to see this code.

     

    Jan... Thank you for keeping developing this :-) - its really easy to use, amazing work.

    As soon EV4 can address the lights via the HueConnector - i will migrate everything to this . 

     

    Enjoy the weekend everyone ?

     

     

    Link to comment
    Share on other sites

  • Topic Author
  • 9 minutes ago, ChristianSogaard said:

    Jan... Thank you for keeping developing this :-) - its really easy to use, amazing work.

    As soon EV4 can address the lights via the HueConnector - i will migrate everything to this . 

     

    Enjoy the weekend everyone ?

     

     

    Thanks, HueSensors is kind of the guinea pig for HueConnector. I have discovered some bugs and I'm still wrestling with HueSensors and HueConnector getting out of sync sometimes- but I'm on to it ;-) 

    • Thanks 1
    Link to comment
    Share on other sites

    • 4 weeks later...

    Jan when do you think that HUEConnector is implemented in ER4?

    Will the rules be similar as COH with a difference to set color in x,y

    Link to comment
    Share on other sites

    Join the conversation

    You can post now and register later. If you have an account, sign in now to post with your account.

    Guest
    Reply to this topic...

    ×   Pasted as rich text.   Paste as plain text instead

      Only 75 emoji are allowed.

    ×   Your link has been automatically embedded.   Display as a link instead

    ×   Your previous content has been restored.   Clear editor

    ×   You cannot paste images directly. Upload or insert images from URL.

    ×
    ×
    • Create New...