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

Converting LUA Scene for Hc3 / Yubii, HELP!


Question

Posted
Hi all, I've tried chat gpt to make a lua script scene for my yubii home, previously 'ive made something on my HC2 with lua but i'm not that confident anymore...
Here's what i've got from chat gpt:
 
 
--[[
Yubii Home Lua Scene for Roller Shutter Control
This scene checks the status of two switches and adjusts the level of a roller shutter according to specific ranges.
]]
-- IDs of the switches and roller shutter device
local switch1ID = 123 -- Replace with actual ID of switch 1
local switch2ID = 456 -- Replace with actual ID of switch 2
local rollerShutterID = 789 -- Replace with actual ID of the roller shutter
-- Function to get the current level of the roller shutter
local function getRollerShutterLevel()
return Yubii.getValue(rollerShutterID, "level")
end
-- Function to set the level of the roller shutter
local function setRollerShutterLevel(level)
Yubii.setValue(rollerShutterID, "level", level)
end
-- Main scene logic
local function main()
local switch1State = Yubii.getValue(switch1ID, "status")
local switch2State = Yubii.getValue(switch2ID, "status")
-- Check if either switch is turned on
if switch1State == "on" or switch2State == "on" then
local currentLevel = getRollerShutterLevel()
-- Adjust the level of the roller shutter based on its current level
if currentLevel >= 0 and currentLevel <= 9 then
setRollerShutterLevel(10)
elseif currentLevel >= 10 and currentLevel <= 49 then
setRollerShutterLevel(50)
elseif currentLevel >= 50 and currentLevel <= 98 then
setRollerShutterLevel(100)
elseif currentLevel >= 99 and currentLevel <= 100 then
setRollerShutterLevel(0)
end
end
end
-- Run the main logic
main()
 
 
Ok the scene look fine to my eyes, but i'm not able so save it in yubii...i see now lua editor is slightly different with condition and function separate... how should i make it work?

5 answers to this question

Recommended Posts

  • 0
Posted (edited)
1 hour ago, calza said:
Hi all, I've tried chat gpt to make a lua script scene for my yubii home, previously 'ive made something on my HC2 with lua but i'm not that confident anymore...
Here's what i've got from chat gpt:
 
 
--[[
Yubii Home Lua Scene for Roller Shutter Control
This scene checks the status of two switches and adjusts the level of a roller shutter according to specific ranges.
]]
-- IDs of the switches and roller shutter device
local switch1ID = 123 -- Replace with actual ID of switch 1
local switch2ID = 456 -- Replace with actual ID of switch 2
local rollerShutterID = 789 -- Replace with actual ID of the roller shutter
-- Function to get the current level of the roller shutter
local function getRollerShutterLevel()
return Yubii.getValue(rollerShutterID, "level")
end
-- Function to set the level of the roller shutter
local function setRollerShutterLevel(level)
Yubii.setValue(rollerShutterID, "level", level)
end
-- Main scene logic
local function main()
local switch1State = Yubii.getValue(switch1ID, "status")
local switch2State = Yubii.getValue(switch2ID, "status")
-- Check if either switch is turned on
if switch1State == "on" or switch2State == "on" then
local currentLevel = getRollerShutterLevel()
-- Adjust the level of the roller shutter based on its current level
if currentLevel >= 0 and currentLevel <= 9 then
setRollerShutterLevel(10)
elseif currentLevel >= 10 and currentLevel <= 49 then
setRollerShutterLevel(50)
elseif currentLevel >= 50 and currentLevel <= 98 then
setRollerShutterLevel(100)
elseif currentLevel >= 99 and currentLevel <= 100 then
setRollerShutterLevel(0)
end
end
end
-- Run the main logic
main()
 
 
Ok the scene look fine to my eyes, but i'm not able so save it in yubii...i see now lua editor is slightly different with condition and function separate... how should i make it work?

Please login or register to see this code.

 

Not tested but should work. 

Edited by Neo Andersson
  • 0
  • Inquirer
  • Posted

    no, it is not working =(

     

    I've put everything in the right column "actions" right?

     

    Tha final main() is useless now?

    • 0
    Posted (edited)

    Please login or register to see this attachment.

     

     

    This is in HC3 scene..this should work...

     

    Replace the switch IDs and shutter id to your

    Edited by Neo Andersson
    • Thanks 1
    • 0
  • Inquirer
  • Posted

    nope =(

     

    It is not getting the right value from the roller shutter...

     

    [ERROR] [SCENE82]: (load):16: attempt to compare number with nil

     

    • 0
  • Inquirer
  • Posted
    14 minutes ago, calza said:

    Sorry, mistake in copying....it is working great! 

    Thanks!!

    14 minutes ago, calza said:

     

     

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