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: mirroring the behavior of the switch connected to the lighting by unconnected one. I need help :(


Question

Posted (edited)

Hello!
I need help to create a scene in which the switch not connected to the light source will imitate the switch that actually turns on this light source. I have a switch (DummySwitch) next to the bed, which I would like to be able to turn off the light controlled by the switch next to the door. Of course, I also need cross on/off possibility: when one can turn off the other.

I did not find similar scene, so I tried to write it myself, but I can't do it  
All in all, everything works except when I'm trying to turn off the light by DummySwitch. 

Please, I need Your Help.

I have a Fibaro HC2 for a few days, and this is the first scene in LUA which I try to make - so please: be gentle ;)

 

--[[
%% properties
740 value
736 value
%% events
%% globals
--]]


-----------------------------------------------------------------------------
  fibaro:debug("SCENE START --------------------------")
  fibaro:debug("sceneInstance: "..fibaro:countScenes())
if 
  fibaro:countScenes() > 1 
 then 
  fibaro:debug("SCENE ABORT --------------------------") 
  fibaro:abort() 
end
------------------------------------------------------------------------------

local startSource = fibaro:getSourceTrigger();

local switchID     = 736
local dummyID    = 740

local switchTurnedOn   =  (tonumber(fibaro:getValue(switchID,  "value")) > 0);
local dummyTurnedOn  =  (tonumber(fibaro:getValue(dummyID, "value")) > 0);

local switchTurnedOff  =  (tonumber(fibaro:getValue(switchID,  "value")) == 0);
local dummyTurnedOff =  (tonumber(fibaro:getValue(dummyID, "value")) == 0);

local isTvLightOn     =  (tostring(fibaro:getGlobal("isTvLightOn")) == "true");
local isTvLightOff    =  (tostring(fibaro:getGlobal("isTvLightOn")) == "false");


if
 switchTurnedOn
  then
   fibaro:debug("isTvLightOn: "..tostring(isTvLightOn))
   fibaro:debug("Real Switch ON - turnOn dummy one")
   fibaro:call(dummyID, "turnOn");
   fibaro:debug("Dummy Switch ON")
   fibaro:setGlobal("isTvLightOn", "true");
   fibaro:debug("isTvLightOn: "..tostring(isTvLightOn))
   fibaro:debug("-changes into:")
   fibaro:debug(fibaro:getGlobal("isTvLightOn"))
  end

 if
  switchTurnedOff and isTvLightOn
   then
    fibaro:debug("isTvLightOn: "..tostring(isTvLightOn))
    fibaro:debug("Real Switch OFF - turnOff dummy one")
    fibaro:call(dummyID, "turnOff");
    fibaro:debug("Dummy Switch OFF")
    fibaro:setGlobal("isTvLightOn", "false");
    fibaro:debug("isTvLightOn: "..tostring(isTvLightOn))
    fibaro:debug("-changes into:")
    fibaro:debug(fibaro:getGlobal("isTvLightOn"))
  end


if
 dummyTurnedOn 
  then
   fibaro:sleep(1000)
    if isTvLightOff
        then
         fibaro:debug("isTvLightOn: "..tostring(isTvLightOn))
         fibaro:debug("Dummy Switch ON - turnOn real one")
         fibaro:call(switchID, "turnOn");
         fibaro:debug("Real Switch ON")
         fibaro:debug("isTvLightOn: "..tostring(isTvLightOn))
         fibaro:debug("-changes into:")
         fibaro:debug(fibaro:getGlobal("isTvLightOn"))
      elseif
         isTvLightOn
        then
         fibaro:abort()
       end
      end

if
 dummyTurnedOff
  then
   fibaro:sleep(1000)
    if isTvLightOn
        then
         fibaro:debug("isTvLightOn: "..tostring(isTvLightOn))
         fibaro:debug("Dummy Switch OFF - turnOff real one")
         fibaro:call(switchID, "turnOff");
         fibaro:debug("Real Switch OFF")
         fibaro:debug("isTvLightOn: "..tostring(isTvLightOn))
         fibaro:debug("-changes into:")
         fibaro:debug(fibaro:getGlobal("isTvLightOn"))
      elseif
         isTvLightOff
        then
         fibaro:abort()
       end
      end

Edited by Fro
typo

2 answers to this question

Recommended Posts

  • 0
Posted (edited)

Please login or register to see this image.

 

Please login or register to see this code.

 

Edited by 10der
  • 0
  • Inquirer
  • Posted

    Superb! Thank You very much!

    Cпасибі!

    • Like 1

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