Help with 1st variable script

Moderator: leecollings

Post Reply
User avatar
blackdog65
Posts: 311
Joined: Tuesday 17 June 2014 18:25
Target OS: Raspberry Pi / ODroid
Domoticz version:
Location: Norfolk, UK
Contact:

Help with 1st variable script

Post by blackdog65 »

Hi guys,

I'm trying to write my first variable script for tracking bluetooth beacons.
My variables update fine but I'm trying to get them to toggle some virtual switches... and my script doesn't work.
Please keep it simple as I'm struggling to get a grip on lua :oops:

I know it's a bit clunky but here it is

Code: Select all

-- script_variable_bt.lua
commandArray = {}

for variableName,variableValue in pairs(uservariablechanged) do
    if (variableName=='Zhenya_Kitchen') then
        if variableValue == HOME then
            commandArray['ZKitchenBT'] = "On"
        end
    end
    if (variableName=='Zhenya_Kitchen') then
        if variableValue == AWAY then
            commandArray['ZKitchenBT'] = "Off"
        end
    end

    if (variableName=='Zhenya_Office') then
        if variableValue == HOME then
            commandArray['ZOfficeBT'] = "On"
        end
    end
    if (variableName=='Zhenya_Office') then
        if variableValue == AWAY then
            commandArray['ZOfficeBT'] = "Off"
        end
    end

    if (variableName=='Zhenya_Hall') then
        if variableValue == HOME then
            commandArray['ZHallBT'] = "On"
        end
    end
    if (variableName=='Zhenya_Hall') then
        if variableValue == AWAY then
            commandArray['ZHallBT'] = "Off"
        end
    end

    if (variableName=='Zhenya_SitRm') then
        if variableValue == HOME then
            commandArray['ZSitRoomBT'] = "On"
        end
    end
    if (variableName=='Zhenya_SitRm') then
        if variableValue == AWAY then
            commandArray['ZSitRoomBT'] = "Off"
        end
    end


end

return commandArray
Many thanks

Sean
CubieTruck Master
RasPi slaves
Aeon Labs Z-Stick, multi sensor
Fibaro Dimmers, relays, Universal sensors
EQ3 MAX!
TKB Sockets
RFXCOM
LightwaveRF sockets, switches, relays, doorbell
MySensors
ESPEasy ESP8266-12E
User avatar
jvdz
Posts: 2334
Joined: Tuesday 30 December 2014 19:25
Target OS: Raspberry Pi / ODroid
Domoticz version: 4.107
Location: Netherlands
Contact:

Re: Help with 1st variable script

Post by jvdz »

Sean,

You are getting errors i guess?
Looks line this line:

Code: Select all

if variableValue == HOME then
Should be this :

Code: Select all

if variableValue == "HOME" then
..and the same for the other if statements.

Jos
New Garbage collection scripts: https://github.com/jvanderzande/GarbageCalendar
User avatar
blackdog65
Posts: 311
Joined: Tuesday 17 June 2014 18:25
Target OS: Raspberry Pi / ODroid
Domoticz version:
Location: Norfolk, UK
Contact:

Re: Help with 1st variable script

Post by blackdog65 »

Yay! :D
jvdz wrote:Sean,

You are getting errors i guess?
Looks line this line:

Code: Select all

if variableValue == HOME then
Should be this :

Code: Select all

if variableValue == "HOME" then
..and the same for the other if statements.

Jos
Many Thanks Jos, worked a treat :D
CubieTruck Master
RasPi slaves
Aeon Labs Z-Stick, multi sensor
Fibaro Dimmers, relays, Universal sensors
EQ3 MAX!
TKB Sockets
RFXCOM
LightwaveRF sockets, switches, relays, doorbell
MySensors
ESPEasy ESP8266-12E
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest