This forum uses cookies
This forum makes use of cookies to store your login information if you are registered, and your last visit if you are not. Cookies are small text documents stored on your computer; the cookies set by this forum can only be used on this website and pose no security risk. Cookies on this forum also track the specific topics you have read and when you last read them. Please confirm that you accept these cookies being set.

Hue Brightness feedback
#1
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

Attached Files Thumbnail(s)
       
Arjen Straver
FMJ Automation
Holland
Reply
#2
Hi Arjen,

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

BR,

Erwin
Reply
#3
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: 148)
.lua   HUE Feedback.lua (Size: 2.14 KB / Downloads: 135)


BR,

Erwin

PS: The function HSB to RGB is not perfect yet but comes close to real color value..
Reply
#4
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%) ?
Reply
#5
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
Reply
#6
(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 !
Reply
#7
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: 112)
.lua   resident hue feedback v2.lua (Size: 5.15 KB / Downloads: 110)
.lua   hue commands v2.lua (Size: 1.96 KB / Downloads: 114)


BR,

Erwin
Reply
#8
(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,

Attached Files Thumbnail(s)
   
Reply
#9
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: 161)
.lua   user.hue v2.lua (Size: 7.62 KB / Downloads: 139)
.lua   hue commands v2.lua (Size: 1.96 KB / Downloads: 162)

BR,

Erwin
Reply
#10
(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!
Reply
#11
(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?
Reply
#12
Try searching all scripts via Scripting > Tools > Print
Reply
#13
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
Reply
#14
(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
Reply
#15
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
Reply
#16
@Erwin van der Zwart: Thank you for this Script! I got it working too (19 Hue Devices) Smile
Reply
#17
Hi,

Your welcome (:

BR,

Erwin
Reply
#18
-- 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?
Reply
#19
What happens when you load the same URL in your browser?
Reply
#20
(30.11.2018, 16:48)admin Wrote: What happens when you load the same URL in your browser?

I get the json
Reply


Forum Jump: