Setting Fibaro Wall Plug Gen5 Switch State

Moderator: leecollings

Post Reply
Wolfgang
Posts: 22
Joined: Saturday 28 October 2017 21:37
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Setting Fibaro Wall Plug Gen5 Switch State

Post by Wolfgang »

Hi ,

I've got a strange problem with a LUA Script on Domoticz 3.8153 .

The Script should set the plug state on
if the Plug "Leistung Steckdose Wohnzimmer Entertainment" has more power than 90 Watt
and the
room brightness of the brightness Sensor is lower than 200 Lux
and the
light on the ceiling is not switched to on.

The script is killing the plug if I set the state with the Content of the variable target_state_stehlampe ( which is On or Off )
but is currently working with the below solution.

Any suggestions why the plug is not responding anymore if the content of the variable is written to the commandarray ?

Below the code of the lua script :

Code: Select all

local debug 
if ( uservariables["GlobalDebug"] == "On" ) then
    debug = true
else
    debug = false
end

local time = os.date("*t")
local energy_level = 90
local brightness_level = 110

function timedifference (s)
  year = string.sub(s, 1, 4)
  month = string.sub(s, 6, 7)
  day = string.sub(s, 9, 10)
  hour = string.sub(s, 12, 13)
  minutes = string.sub(s, 15, 16)
  seconds = string.sub(s, 18, 19)
  t1 = os.time()
  t2 = os.time{year=year, month=month, day=day, hour=hour, min=minutes, sec=seconds}
  difference = os.difftime (t1, t2)
  return difference
end


commandArray = {}

local room_brightness = otherdevices_svalues["Helligkeit Sensor Balkon Aussen"]
local state_stehlampe = otherdevices['Licht Wohnzimmer Stehlampe']
local target_state_stehlampe = ""
if not room_brightness or room_brightness == ''  then 
    if debug == true then
        print ("Raum Helligkeit       : Kein Wert verfügbar" )
    end
    room_brightness = "200"
end
local tv_energy         = otherdevices_svalues["Leistung Steckdose Wohnzimmer Entertainment"]
local state_licht_decke = otherdevices['Niveau Licht Wohnzimmer']

if debug == true then
    print ("WoZi Energie        : " .. tostring(tonumber(tv_energy )))
    print ("WoZi Energielevel   : " .. energy_level )
    print ("WoZi Dimmer State   : " .. state_licht_decke )
    print ("WoZi Helligkeit     : " .. room_brightness )    
    print ("WoZi Stehlampe      : " .. state_stehlampe )    

end
if (tonumber(room_brightness) < brightness_level ) then
    target_state_stehlampe = 'On' 
    if debug == true then
        print ("Raum zu dunkel    : Stehlampe ein" )
    end
end
    
    
if (tonumber(tv_energy) < tonumber(energy_level) ) then
    target_state_stehlampe ='Off'
    if debug == true then
        print ("Leistung Entertainment zu klein    : Stehlampe aus" )
    end
       
end

if (tonumber(room_brightness) > brightness_level ) then
    target_state_stehlampe ='Off'
    if debug == true then
        print ("Raum zu Hell    : Stehlampe aus" )
    end
       
end

if (state_licht_decke ~= 'Off' ) then
    if debug == true then
            print ("Deckenbeleuchtung ein erkannt" )
            print ("Stehlampen Status         : " .. state_stehlampe )
            print ("Stehlampe State gewünscht : " .. target_state_stehlampe )
    end
    target_state_stehlampe = 'Off'
    if debug == true then
        print ("Deckenbeleuchtung ein   : Stehlampe aus" )
    end
end

if otherdevices['Licht Wohnzimmer Stehlampe'] ~= target_state_stehlampe then

--    not working 
--     commandArray['Licht Wohnzimmer Stehlampe'] = target_state_stehlampe 

        if (target_state_stehlampe == 'On') then 
              commandArray['Licht Wohnzimmer Stehlampe'] = 'On'
        end
        if (target_state_stehlampe == 'Off') then 
              commandArray['Licht Wohnzimmer Stehlampe'] = 'Off'
        end
        if debug == true then
            print ("Stehlampe Wohnzimmer State Change    : " .. target_state_stehlampe )
        end
else
        if debug == true then
            print ("Stehlampe Wohnzimmer State Change not needed   : " .. target_state_stehlampe )
        end
end
return commandArray
Post Reply

Who is online

Users browsing this forum: hjzwiers and 1 guest