Page 1 of 1

script does not work

Posted: Sunday 25 February 2018 12:04
by pvklink
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
}

Re: script does not work

Posted: Sunday 25 February 2018 12:15
by dannybloe
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.

Re: script does not work

Posted: Sunday 25 February 2018 12:37
by pvklink
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
}

Re: script does not work

Posted: Sunday 25 February 2018 13:28
by dannybloe
Read the troubleshooting section in the documentation. That might help.

Re: script does not work

Posted: Wednesday 28 February 2018 12:24
by pvklink
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

Re: script does not work

Posted: Wednesday 28 February 2018 14:06
by elmortero
http://www.domoticz.com/forum/viewforum.php?f=59

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

Re: script does not work

Posted: Monday 05 March 2018 20:49
by pvklink
thanks!

Re: script does not work

Posted: Saturday 05 May 2018 13:19
by elmortero
pvklink wrote: Monday 05 March 2018 20:49thanks!
Got it working?