Simple? LUA for tellstick.net zwave

Moderator: Telldus

Post Reply
jonasmj
Posts: 4
Joined: Fri Mar 17, 2023 9:45 am

Simple? LUA for tellstick.net zwave

Post by jonasmj »

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: 15
Joined: Fri Mar 17, 2023 9:45 am

Re: Simple? LUA for tellstick.net zwave

Post by geirbakkw »

Change the command from turn off to turnoff without space.
fcorin
Posts: 19
Joined: Fri Mar 17, 2023 9:45 am

Re: Simple? LUA for tellstick.net zwave

Post by fcorin »

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: Fri Mar 17, 2023 9:45 am

Re: Simple? LUA for tellstick.net zwave

Post by jonasmj »

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: 19
Joined: Fri Mar 17, 2023 9:45 am

Re: Simple? LUA for tellstick.net zwave

Post by fcorin »

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