Logic Machine Forum
Hue Brightness feedback - Printable Version

+- Logic Machine Forum (https://forum.logicmachine.net)
+-- Forum: LogicMachine eco-system (https://forum.logicmachine.net/forumdisplay.php?fid=1)
+--- Forum: Scripting (https://forum.logicmachine.net/forumdisplay.php?fid=8)
+--- Thread: Hue Brightness feedback (/showthread.php?tid=890)

Pages: 1 2 3 4


Hue Brightness feedback - Arjen Straver - 05.07.2017

Hi to all,

I've a good working LM3 with some Hue lights with brightness feedback. So I tought i'll copy / paste the script into a LM5

Now there's a error into the script:

Resident script:97: Expected object key string but found unexpected end of string at character 2049
stack traceback:
[C]: in function 'decode'


What's wrong? ( the user lib. script is the same, except the IP-adres and user name) 

I can control the Hue's from my LM5 but there's no feedback.


Greetz,

Arjen


RE: Hue Brightness feedback - Erwin van der Zwart - 05.07.2017

Hi Arjen,

I created this HUE feedback script for Peter (FMJ), please let him call me tommorow so i can support him.

BR,

Erwin


RE: Hue Brightness feedback - Erwin van der Zwart - 06.07.2017

Hi Arjen,

As discussed you where using a old version of the HUE feedback. Here is the latest version with fix when using more lamps (the result table existed out of multiple tables).
.lua   HUE User Lib.lua (Size: 5.59 KB / Downloads: 153)
.lua   HUE Feedback.lua (Size: 2.14 KB / Downloads: 138)


BR,

Erwin

PS: The function HSB to RGB is not perfect yet but comes close to real color value..


RE: Hue Brightness feedback - Hippolyte - 19.07.2017

Hello everyone,

The colour changing works like a charm ! Thank you for the library.
Do you know if it's possible to do simple dimming (0-100%) ?


RE: Hue Brightness feedback - Erwin van der Zwart - 19.07.2017

Hi,

Use:

Code:
require('user.hue')
value = event.getvalue()
lamp_id = 1

value=math.floor(value*2.55)

if value == 0 then
 body_msg = '{"on":false}'
 sendToLight(lamp_id,body_msg)
else
 body_msg = '{"on":true,"bri":'..value..'}'
 sendToLight(lamp_id,body_msg)
end
BR,

Erwin


RE: Hue Brightness feedback - Hippolyte - 27.07.2017

(19.07.2017, 16:02)Erwin van der Zwart Wrote: Hi,

Use:

Code:
require('user.hue')
value = event.getvalue()
lamp_id = 1

value=math.floor(value*2.55)

if value == 0 then
 body_msg = '{"on":false}'
 sendToLight(lamp_id,body_msg)
else
 body_msg = '{"on":true,"bri":'..value..'}'
 sendToLight(lamp_id,body_msg)
end
BR,

Erwin

Thank you Erwin !


RE: Hue Brightness feedback - Erwin van der Zwart - 25.10.2017

Hi,

There are some questions about HUE because there are some older libs and samples so here is the latest version to avoid all kind of questions:
.lua   user.hue v2.lua (Size: 7.62 KB / Downloads: 114)
.lua   resident hue feedback v2.lua (Size: 5.15 KB / Downloads: 112)
.lua   hue commands v2.lua (Size: 1.96 KB / Downloads: 116)


BR,

Erwin


RE: Hue Brightness feedback - Albertor - 21.11.2017

(25.10.2017, 17:20)Erwin van der Zwart Wrote: Hi,

There are some questions about HUE because there are some older libs and samples so here is the latest version to avoid all kind of questions:


BR,

Erwin

Good afternoon,
I have an application with enough Hue's. Everything works fine, but I have a problem with feedbacks ... I'm using v2. Attached image of the error.

Here is the error: Resident scritp21: bad argument # 1 to 'decode' (string expected, got table)
stack traceback:
[C]: in function 'decode'

Thank you very much for your help!!
Regards,


RE: Hue Brightness feedback - Erwin van der Zwart - 21.11.2017

Hi,

Can you try the latest version, it has some minor improvemments including the fix for this issue when feedback exceeds 1000 chars.
.lua   resident hue feedback v2.lua (Size: 5.15 KB / Downloads: 164)
.lua   user.hue v2.lua (Size: 7.62 KB / Downloads: 142)
.lua   hue commands v2.lua (Size: 1.96 KB / Downloads: 165)

BR,

Erwin


RE: Hue Brightness feedback - Albertor - 22.11.2017

(21.11.2017, 23:07)Erwin van der Zwart Wrote: Hi,

Can you try the latest version, it has some minor improvemments including the fix for this issue when feedback exceeds 1000 chars.

BR,

Erwin
Hi Erwin,

I think so, it's the same script as the link in post # 7, right?

thanks!


RE: Hue Brightness feedback - DarthPaul - 13.08.2018

(21.11.2017, 23:07)Erwin van der Zwart Wrote: Hi,

Can you try the latest version, it has some minor improvemments including the fix for this issue when feedback exceeds 1000 chars.

BR,

Erwin

Hello

I am using the latest version. And it works perfect. The only issue I can't figure out, is that it is filling up my LOG.

I have qouted all script part with -- log(something) but the script fill up my log with 
*string: hue = 40712
*string: colormode = xy
*string: bri = 136
etc..
seems to come from all lamps defined in script..

I can not find any referende in script, why this is logged.. Does something in require log to the log file?
Like require('json')
socket.http or ltn12?

Or is it some other LUA code that also write into log-file? like sink, respone or similar?
I really cant find it (i quoted absolutely all log()) and still the meassages fill up?

I copyed all files from you Erwin
Any Idea why?


RE: Hue Brightness feedback - admin - 13.08.2018

Try searching all scripts via Scripting > Tools > Print


RE: Hue Brightness feedback - Erwin van der Zwart - 13.08.2018

Hi,

Try restarting the script, there is a “do while” in the feedback script so changing anything without restarting it won’t be loaded until a restart of the script.

BR,

Erwin


RE: Hue Brightness feedback - DarthPaul - 14.08.2018

(13.08.2018, 21:34)Erwin van der Zwart Wrote: Try restarting the script, there is a “do while” in the feedback script so changing anything without restarting it won’t be loaded until a restart of the script.

Thanks! That solved the issue.. 
It almost made me go crazy!
I assumed it restarted, when i edited script and saved it.. but that do while-forever loop, probably got stuck?
Your the Best!  Smile


RE: Hue Brightness feedback - Erwin van der Zwart - 14.08.2018

Hi,

No it doesn’t get stuck, it’s just the logical behavior of a script when you use a ‘do while’, as long as the conditions are valid it will keep doing what it’s been told, if you change the script in the background it doesn’t load that until the next time it should restart, or forced by a manual restart.

BR,

Erwin


RE: Hue Brightness feedback - ralwet - 19.10.2018

@Erwin van der Zwart: Thank you for this Script! I got it working too (19 Hue Devices) Smile


RE: Hue Brightness feedback - Erwin van der Zwart - 19.10.2018

Hi,

Your welcome (:

BR,

Erwin


RE: Hue Brightness feedback - FatMax - 30.11.2018

-- THE POST BELOW HAS BEEN EDITED. THE CODE NOW WORKS AS EXPECTED AND EDITED AS SUCH --

I've been using this library for a while at home and have had no problems with it on my own SL.

I made this function that I added to the hue feedback function library:

Code:
function getBri(Light_num)
 local response = {}
 socket.http.request({
 url = "http://"..ip_add.."/api/"..user.."/lights/"..tostring(Light_num),
 method = 'GET',
 sink = ltn12.sink.table(response),
 headers = {
       ['content-type'] = 'application/json',
 },
     source = ltn12.source.string(),
 })
 return response
end

The purpose was to be able to dim with standard KNX. This works well in my home with this script (attached to dim GA):

Code:
require('json')

-- Lamp id
lamp_id = 1

-----------------------------------------
start = event.getvalue()
val = getBri(lamp_id)
result = table.concat(val)
json_data = json.pdecode(result)
bri = tonumber(json_data.state.bri)

-- DIM Philips HUE Up

if start == 09 then
  
value = bri + 30
  
body_msg = '{"on":true,"bri":'..value..'}' 

sendToLight(lamp_id,body_msg)

-- DIM Philips HUE Down
 
elseif start == 01 then
 
value = bri - 30

body_msg = '{"on":true,"bri":'..value..'}' 
sendToLight(lamp_id,body_msg)

end
-----------------------------------------

I tried loading this onto our demo "apartment" SL in our office and I'm having a problem getting the desired result. The error log outputs this when trying to run it:

Code:
* table:
[1]
 * string: <html>
<head><title>400 Bad Request</title></head>
<body bgcolor="white">
<center><h1>400 Bad Request</h1></center>
<hr><center>nginx</center>
</body>
</html>

I´m expecting a JSON table, so that I can get to the Bri variable. 

At home I have a v1 HUE hub and HW2 SL. At the office we have a v2 HUE hub and HW3 Wiser. Is the problem simply the ltn12 vs. ssl.http? I've tried to change that, but to no avail.

Any tips?


RE: Hue Brightness feedback - admin - 30.11.2018

What happens when you load the same URL in your browser?


RE: Hue Brightness feedback - FatMax - 01.12.2018

(30.11.2018, 16:48)admin Wrote: What happens when you load the same URL in your browser?

I get the json