Simple? LUA for tellstick.net zwave

Moderator: Telldus

Post Reply
jonasmj
Posts: 4
Joined: Thu Jan 18, 2018 11:08 am

Simple? LUA for tellstick.net zwave

Post by jonasmj » Thu Jan 18, 2018 11:08 am

I am trying to turn of a Nexa on/off switch whenever it is turned on. Reason is that I try to emulate a momentary switch to trigger a relay. (in practical getting the switch would close about 1-3 seconds after pressed "on" in tellstick.net)
I am a total beginner and below code is my very first LUA-attempt. I get the output "Script relay.lua loaded" from running it but absolutely nothing happens. What am I doing wrong?

Code: Select all

-- File: relay.lua

local deviceManager = require 'telldus.DeviceManager'
local breaker = 'Nexa ZW 1' --Nexa AN179 z-wave on/off switch
                     
    function onDeviceStateChanged(device, state, stateValue)

       local breaker = deviceManager:findByName(breaker)
       		if breaker == nil then
            	print('Breaker seems lost...')
          	return
          	end
              
       		if (breaker:state() == 'On') then
        		breaker:command('turn off', nil, 'breaker')    
			return
       		end
      end 

geirbakkw
Posts: 14
Joined: Thu Jan 18, 2018 11:08 am

Re: Simple? LUA for tellstick.net zwave

Post by geirbakkw » Thu Jan 18, 2018 11:08 am

Change the command from turn off to turnoff without space.

fcorin
Posts: 12
Joined: Thu Jan 18, 2018 11:08 am

Re: Simple? LUA for tellstick.net zwave

Post by fcorin » Thu Jan 18, 2018 11:08 am

Code: Select all


local deviceManager = require 'telldus.DeviceManager'
local breaker = 'Nexa ZW 1' --Nexa AN179 z-wave on/off switch
                 
function onDeviceStateChanged(device, state, stateValue)

    if (device:name() ~= breaker) then
        return
    end

    if (device:state()==1) then
        device:command('turnoff', nil, 'breaker')
    end

end
Or look at this example if you want to control the time the unit is on: https://github.com/telldus/tellstick-lu ... eTimer.lua
--
Fredrik

jonasmj
Posts: 4
Joined: Thu Jan 18, 2018 11:08 am

Re: Simple? LUA for tellstick.net zwave

Post by jonasmj » Thu Jan 18, 2018 11:08 am

fcorin wrote:

Code: Select all


local deviceManager = require 'telldus.DeviceManager'
local breaker = 'Nexa ZW 1' --Nexa AN179 z-wave on/off switch
                 
function onDeviceStateChanged(device, state, stateValue)

    if (device:name() ~= breaker) then
        return
    end

    if (device:state()==1) then
        device:command('turnoff', nil, 'breaker')
    end

end
Thanks! Works fine.
Or look at this example if you want to control the time the unit is on: https://github.com/telldus/tellstick-lu ... eTimer.lua
Also tried the timer code. Put in 0 sec and that give the same result. About 3,5 sec on before off. Any way to reduce the time possible? Or is the tellstick/zwave system limited in some way?

fcorin
Posts: 12
Joined: Thu Jan 18, 2018 11:08 am

Re: Simple? LUA for tellstick.net zwave

Post by fcorin » Thu Jan 18, 2018 11:08 am

I guess the best way would be to get a device where you can set a parameter for auto off. That way the controller won't cause any delay.
--
Fredrik

Post Reply