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


  • 0

Scene that runs only if the light level is below a user set


emariu

Question

I found some LUA code for VERA that would run a scene only if the light level is below a user set threshold :

local LOW_LEVEL = 20 -- the light level threshold for night

local DEVICE_NO = 33 -- the light sensor device number

local LS_SID = "urn:micasaverde-com:serviceId:LightSensor1" -- the LightSensor service ID

local currentLevel = luup.variable_get (LS_SID, "CurrentLevel", DEVICE_NO) or 0

currentLevel = tonumber(currentLevel)

if currentLevel <= LOW_LEVEL then

return true

else

return false

end

Can someone tell me how can I implement this function for HC2?

Link to comment
Share on other sites

10 answers to this question

Recommended Posts

  • 0

Hi there,

What is your setup?

I do not have a light sensor but I am using HC2 built in sunsethour and sunrisehour functions to enable/trigger certain devices at home. These functions return the correct sunset/sunrise hour based on the longitude/lattitude you specify in your location settings. Add a margin to those hours and you can perfectly achieve something similar without the need of a light sensor.

Please see my detailed response in

Please login or register to see this link.

thread.

As for a light sensor, I would assume that you can simply add it as the first condition in the visual scene builder: IF LIGHT SENSOR <= NUMBER (where NUMBER = the amount of lumen, 200 for example) THEN do stuff.

Jan

Link to comment
Share on other sites

  • 0
  • Inquirer
  • Hi there,

    What is your setup?

    I do not have a light sensor but I am using HC2 built in sunsethour and sunrisehour functions to enable/trigger certain devices at home. These functions return the correct sunset/sunrise hour based on the longitude/lattitude you specify in your location settings. Add a margin to those hours and you can perfectly achieve something similar without the need of a light sensor.

    Please see my detailed response in

    Please login or register to see this link.

    thread.

    As for a light sensor, I would assume that you can simply add it as the first condition in the visual scene builder: IF LIGHT SENSOR <= NUMBER (where NUMBER = the amount of lumen, 200 for example) THEN do stuff.

    Jan

    I have an AEOTEC 4-1 with light sensor ,so I want to light on a lamp if the lumens are below 125(stormy days are dark, so sunset isn't a good option for me).

    I didn't realize that I have visual scene builder: IF LIGHT SENSOR <= NUMBER ..so I tried to do the scene but when I select light sensor >= there is only ON/breached/armed .... options,but don't let me input numbers for actual light conditions.

    So,what option do I have ?

    Link to comment
    Share on other sites

    • 0
    Guest b95_lun

    I have a scene that sets a global variable to brigh or dark depending on the lux reporter by 4-1 sensor.

    I then have other scenes that will use this variable. For example I will turn on outside light if it is dark and not night.

    I use lua in the scenes, i don't know if you can do it with the graphic block style

    Link to comment
    Share on other sites

    • 0
  • Inquirer
  • I have a scene that sets a global variable to brigh or dark depending on the lux reporter by 4-1 sensor.

    I then have other scenes that will use this variable. For example I will turn on outside light if it is dark and not night.

    I use lua in the scenes, i don't know if you can do it with the graphic block style

    Please send me the LUA code that reads lux reported..Iwant to use your exact code..Thanks

    Link to comment
    Share on other sites

    • 0
    Guest b95_lun

    Here the code that reads the lux value and sets the global variables

    Device 45 is the 4-1 sensor

    Global variable = ljusUte (Swedish for light outside). Has two values mörkt (dark) and ljust (bright)

    I then have other scenes that watch this global variable and takes action when it is changed.

    I hope this helps

    Please login or register to see this code.

    Link to comment
    Share on other sites

    • 0
  • Inquirer
  • Here the code that reads the lux value and sets the global variables

    Device 45 is the 4-1 sensor

    Global variable = ljusUte (Swedish for light outside). Has two values mörkt (dark) and ljust (bright)

    I then have other scenes that watch this global variable and takes action when it is changed.

    I hope this helps

    Please login or register to see this code.

    "Device 45 is the 4-1 sensor" ...is not device 41 the light sensor?

    What is this for :"local iOsDevice =42" ?

    What changes do I have to do for this to work with my device?Here: "trigger["deviceID"]" am I supposed to change anything?

    Thank you again for your help

    Link to comment
    Share on other sites

    • 0
    Guest b95_lun

    Sorry I was a made a typo, 41 is the sensor.

    The iOSdevice was the id for my iPhone, I used a push notification for testing proposes but it isn't used any more.

    The changes you need to do is the sensor id (change 41 to your sensor id) and change the global variable (ljusUte) and its values unless you want it in swedish.

    Link to comment
    Share on other sites

    • 0
  • Inquirer
  • Sorry I was a made a typo, 41 is the sensor.

    The iOSdevice was the id for my iPhone, I used a push notification for testing proposes but it isn't used any more.

    The changes you need to do is the sensor id (change 41 to your sensor id) and change the global variable (ljusUte) and its values unless you want it in swedish.

    I changed that and after I had pushed the RUN scene button and I got some error response : [ERROR] 13:44:10: line :getValue (arg 2), expected 'unsigned int' got 'nil'

    [ERROR] 13:44:16: line :getValue (arg 2), expected 'unsigned int' got 'nil'

    Maybe I was not supposed to push the RUN (or Start) button

    Please login or register to see this image.

    /emoticons/default_smile.png" alt=":)" srcset="https://forum.fibaro.com/uploads/emoticons/[email protected] 2x" width="20" height="20" />

    Is the scene supposed to run on every HC2 restart?

    Link to comment
    Share on other sites

    • 0
    Guest b95_lun

    Hi,

    As the scene isbuilt you can't run it.

    The scene is triggered by a change of the value of the sensor

    The definition of the variable trigger requires that a change of the valu has happened.

    Please login or register to see this code.

    when you use run no change of the value has happened thus the local fibaro:getSourceTrigger() will be nill and you get an eror during execution.

    Link to comment
    Share on other sites

    • 0
  • Inquirer
  • All is working fine now, very happy

    Please login or register to see this image.

    /emoticons/default_smile.png" alt=":)" srcset="https://forum.fibaro.com/uploads/emoticons/[email protected] 2x" width="20" height="20" />

    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
    Answer this question...

    ×   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...