script does not work

Easy to use, 100% Lua-based event scripting framework.
Post Reply
pvklink
Posts: 142
Joined: Wednesday 12 November 2014 16:01
Target OS: Raspberry Pi
Domoticz version:
Contact:

script does not work

Post by pvklink » Sunday 25 February 2018 13:04

latest beta domoticz.
script does not update my sensor "temperatuur".
I made this script with
event: test3
dzVents
Timer. (but after saving it becomes devices automaticaly ?

I have this script working with lua, but i dont want it every minute but every hour.

Functionality
1. i read a station.sensor (buitentemperatuur), This station has two values, i need the first, the temperature
2. i read the temperature and put it in a temperature sensor "temperatuur"
3. If the value "temperatuur" is below 3 degrees celcius and warmtelint is off, warmtelint will be on (some kind of heater againt freezing the watersupply)

Code: Select all


return {
    	active = true,
    on = {
        timer = {'every 60 minutes'}
        },

execute = function(domoticz)
        local schakelaar = 'warmtelint'             -- schakelaar van warmtelint
        local sensortemp = 'Buitentemperatuur'      -- sensor die de weergegevens ontvangt
        local templimit = 3                         -- tempwaarde onderwaarde

        sTemp, sWeatherHumidity = otherdevices_svalues[sensortemp]:match("([^;]+);([^;]+);([^;]+)")
        sTemp = tonumber(sTemp)
        domoticz.temperatuur.temperature=sTemp -- set a sensor with only the temperature from sensor buitentemperatuur. Sensor buitentemperatuur is multi valued

        if (sTemp) <= 3 then
            -- temperatuur is onder de minimumwaarde
            if (warmtelint.active) then
                domoticz.log('Warmtelint stond al aan')
            else
                domoticz.devices(schakelaar).switchOn()
                domoticz.log('Warmtelint aan')
            end
        else
            -- temperatuur is boven of gelijk aan de minimumwaarde
            if (warmtelint.active) then
                domoticz.log('Warmtelint stond aan wordt nu uitgezet')
                domoticz.devices(schakelaar).switchOff()
            else
                domoticz.log('Warmtelint was al uit')
            end
        end
end
}
Last edited by pvklink on Sunday 25 February 2018 13:22, edited 3 times in total.

dannybloe
Posts: 1486
Joined: Friday 29 August 2014 11:26
Target OS: Raspberry Pi
Domoticz version:
Location: Ermelo
Contact:

Re: script does not work

Post by dannybloe » Sunday 25 February 2018 13:15

First of all, use code blocks in the editor here to make your code actually readable.

Second, don't use other_devices. That won't work. All the necessary information is in the device object.

Third: domoticz.temperatuur.temperature=sTemp
That doesn't work either. domoticz.temperatuur does not exist and setting it is not something you should do. Please read the documentation and read about how the domoticz object works that is passed to your execute function. In that object is a devices collection that you can use to get hold of your sensors.

Cheers.
Creator dzVents - RPi3, loads of zwave devices, esp8266, evohome.

pvklink
Posts: 142
Joined: Wednesday 12 November 2014 16:01
Target OS: Raspberry Pi
Domoticz version:
Contact:

Re: script does not work

Post by pvklink » Sunday 25 February 2018 13:37

I think i have bigger problems...
Dzvents does not work at all....
when i add a simple script, it does not work....
when turning on/off a device.. no entry in the logfile

Code: Select all

return {
	on = {
		devices = {
			'Lantaarn'
		}
	},
	execute = function(domoticz, device)
		domoticz.log('Device ' .. device.name .. ' was changed', domoticz.LOG_INFO)
	end
}

dannybloe
Posts: 1486
Joined: Friday 29 August 2014 11:26
Target OS: Raspberry Pi
Domoticz version:
Location: Ermelo
Contact:

Re: script does not work

Post by dannybloe » Sunday 25 February 2018 14:28

Read the troubleshooting section in the documentation. That might help.
Creator dzVents - RPi3, loads of zwave devices, esp8266, evohome.

pvklink
Posts: 142
Joined: Wednesday 12 November 2014 16:01
Target OS: Raspberry Pi
Domoticz version:
Contact:

Re: script does not work

Post by pvklink » Wednesday 28 February 2018 13:24

problems solved, installed python again...

I got my lua script working to extract the temp from my wheatersensor.
I like to learn how to convert this to a dzvents script.
Is there a guide which commands have to be changed?

Code: Select all

--script met eigen weerstation
--eerst waarde afpellen omdat er meerdere waarde worden meegegeven zie hardwareoverzicht

local weersensor = 'Buitentemperatuur'  -- sensor die de gecombineerde weergegevens ontvangt van lidl buitensensor
local switchlint = 'warmtelint'         -- schakelaar die bij onderschreiding temperatuur aangezet wordt
local idxt = 394                        -- idx van afgepelde sensor met alleen de numerieke waarde van de temperatuur, volgens mij altijd een extra ;([^;]+)
local templimit = 3                     -- minimale onderwaarde temperatuur
local timeofflimit = 1000               -- minimale onderwaarde in tijd voordat de switch mag worden uitgezet

function round2(num, numDecimalPlaces)
  return tonumber(string.format("%." .. (numDecimalPlaces or 0) .. "f", num))
end

commandArray = {}

if devicechanged[weersensor] then
    curTemp, curHumidity = otherdevices_svalues[weersensor]:match("([^;]+);([^;]+);([^;]+)")
    curTemp =  round2(tonumber(curTemp),1)
        
    if curTemp == nil then
            print ('01 Temperatuur van weersensor: '.. weersensor .. ' heeft geen waarde opgehaald !')
    else
        curoldtemp = round2(tonumber(otherdevices_svalues["temperatuur"]),1)
        if (curTemp < curoldtemp) or (curTemp > curoldtemp) then
            commandArray[1] = {['UpdateDevice'] = idxt .. '|0|' .. curTemp}     -- bijwerken gestripte temperatuursensor (nog aanpassen dat dit alleen gebeurd als waarde is veranderd)
            if curTemp <= templimit then
                if otherdevices[switchlint] == 'On' then
                    print ('02 Temperatuur ' .. tostring(curTemp) ..' <= dan '.. tostring(templimit) .. ', warmtelint stond al aan, blijft aan')
                elseif otherdevices[switchlint] == 'Off' then
                    print ('03 Temperatuur ' .. tostring(curTemp) ..' <= dan '.. tostring(templimit) .. ', warmtelint is uit, wordt aangezet')
                    commandArray[switchlint]='On' 
                    --commandArray['Lantaarn']='On' -- deze mag later weg. neem een contact met stroomverbruik
                end
            else
                if otherdevices[switchlint] == 'Off' then
                    print ('04 Temperatuur ' .. tostring(curTemp) ..' > dan '.. tostring(templimit) .. ', warmtelint stond al uit, blijft uit')
                elseif otherdevices[switchlint] == 'On' then
        
                    s = otherdevices_lastupdate[switchlint]         -- returns a date time like 2013-07-11 17:23:12
                    t1 = os.time()
                    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)
                    t2 = os.time{year=year, month=month, day=day, hour=hour, min=minutes, sec=seconds}
                    difference = (os.difftime (t1, t2))
                    hulpdiff = round2(difference / 60,2)
                    --hulpdiff = difference / 60
                
                    if difference < timeofflimit then               -- eerst check of hij al minimaal een uur aanstaat anders niets doen ! teveel aanuit is slecht voor lint
                        print ('05 Temperatuur ' .. tostring(curTemp) ..' groter dan '.. tostring(templimit) .. ', warmtelint is ' .. tostring(hulpdiff) ..' minuten aan, dus nog niet uitzetten')
                    else
                        print ('06 Temperatuur ' .. tostring(curTemp) ..' groter dan '.. tostring(templimit) .. ', warmtelint was ' .. tostring(hulpdiff) ..' minuten aan, en wordt uitgezet')
                        commandArray[switchlint]='Off' 
                        --commandArray['Lantaarn']='Off' -- deze mag later weg. neem een contact met stroomverbruik
                    end 
                end
            end
        else    
            --print ('07 Temperatuur oude temp' .. tostring(curoldtemp) ..' en nieuwe temperatuur' .. tostring(curTemp) .. ' zijn gelijk')
        end        
    end
end

return commandArray

elmortero
Posts: 241
Joined: Sunday 29 November 2015 21:46
Target OS: Raspberry Pi
Domoticz version: 3.9639
Location: Spain
Contact:

Re: script does not work

Post by elmortero » Wednesday 28 February 2018 15:06

http://www.domoticz.com/forum/viewforum.php?f=59

The first 3 topics should be all you need to get started

pvklink
Posts: 142
Joined: Wednesday 12 November 2014 16:01
Target OS: Raspberry Pi
Domoticz version:
Contact:

Re: script does not work

Post by pvklink » Monday 05 March 2018 21:49

thanks!

elmortero
Posts: 241
Joined: Sunday 29 November 2015 21:46
Target OS: Raspberry Pi
Domoticz version: 3.9639
Location: Spain
Contact:

Re: script does not work

Post by elmortero » Saturday 05 May 2018 13:19

pvklink wrote:
Monday 05 March 2018 21:49
thanks!
Got it working?

Post Reply

Who is online

Users browsing this forum: No registered users and 2 guests