Execute a script only once on 20seconds

Moderator: leecollings

Post Reply
javed222pi
Posts: 7
Joined: Monday 29 August 2016 13:29
Target OS: Raspberry Pi / ODroid
Domoticz version: 3.4834
Location: Argentina
Contact:

Execute a script only once on 20seconds

Post by javed222pi »

Hello, I new in lua, and i need help for modify this scrip for execute command every 20 seconds
Please Help!

Thanks

Code: Select all

--[[script_time_export_emoncms.lua
auteur : papoo
version : 1.00
date : 18/05/2016
Principe : 
exporter les donn�es de compteurs, Temp�ratures, etc.. sur le site https://emoncms.org/
Le script est lu toutes les minutes mais n'exporte les donn�es que toutes les 2 minutes (temps modifiable ligne 74)
]]--
-- ============================================================================
-- Variables 
local debugging = false  -- true ou false

local url_emoncms = 'http://emoncms.org/api/' 
local API_key = 'xxxxxxxxxxxxxxxxxxxxxxxxxxx' -- API Write KEY emoncms 32 charact�res

local les_devices = {}; 

les_devices[1] = {name="HeatIt_play - Temperatura"} 
les_devices[2] = {name="HeatIt_living - Temperatura"}  
les_devices[3] = {name="HeatIt_ppal - Temperatura"}
les_devices[4] = {name="sensor pergola - TempHum"}
les_devices[5] = {name="hem3 - Total Whatts"}

local fields =""
-- ============================================================================
commandArray = {}
function voir_les_logs (s)
    if (debugging) then 
        print ("<font color='#f3031d'>".. s .."</font>");
    end
end   
function sans_accent(str)
    if (str) then
   str = string.gsub (str,"�", "C")
   str = string.gsub (str,"�", "c")
    str = string.gsub (str,"[-����']+", "e")
   str = string.gsub (str,"[-����']+", "E")
    str = string.gsub (str,"[-������']+", "a")
    str = string.gsub (str,"[-@������']+", "A")
    str = string.gsub (str,"[-����']+", "i")
    str = string.gsub (str,"[-����']+", "I")
    str = string.gsub (str,"[-������']+", "o")
    str = string.gsub (str,"[-�����']+", "O")
    str = string.gsub (str,"[-����']+", "u")
    str = string.gsub (str,"[-����']+", "U")
    str = string.gsub (str,"[-��']+", "y")
    str = string.gsub (str,"�", "Y")
     end
    return (str)
end

function urlencode(str)
   if (str) then
   str = string.gsub (str, "\n", "\r\n")
   str = string.gsub (str, "([^%w ])",
   function (c) return string.format ("%%%02X", string.byte(c)) end)
   str = string.gsub (str, " ", "+")
   end
   return str
end 

now=os.date("*t")
if now.min % 1 == 0 then  -- Exportar datos a emoncms cada 1 min
print('export_emoncms.lua')
         voir_les_logs("--- --- --- Export vers emoncms  : "..now.hour.. ":" ..now.min,debugging);

    for i,d in ipairs(les_devices) do
    v=otherdevices[d.name]                        -- v is the value attached to device d
         voir_les_logs(sans_accent(d.name).." = "..(v or "nil"),debugging);
       if v==nil or v=="" or v=="Open" then                  -- multi valued ?
        v=otherdevices_svalues[d.name] or ""
       voir_les_logs("--- --- --- ".. sans_accent(d.name) .." = ".. v,debugging);
       end
      fields = fields .. '{'.. d.name .. ':' .. v .. '},'
   
   end
      fields = string.gsub (fields, ",$", "") -- quitar la última coma
      fields = urlencode(sans_accent(fields)) -- Remover acentos caracteres acentuados
       voir_les_logs("--- --- --- ".. url_emoncms ..'post?apikey=' .. API_key .. '&json=' .. fields ,debugging);
   commandArray[1]={['OpenURL']=url_emoncms ..'post?apikey=' .. API_key .. '&json=' .. fields }   
end -- if now
-- ============================================================================
return commandArray
User avatar
Egregius
Posts: 2582
Joined: Thursday 09 April 2015 12:19
Target OS: Linux
Domoticz version: v2024.7
Location: Beitem, BE
Contact:

Re: Execute a script only once on 20seconds

Post by Egregius »

Either you set it as a device script and update a dummy device every 20 seconds.
Or use another language outside of domoticz.
User avatar
mcestoni
Posts: 11
Joined: Tuesday 08 August 2017 3:19
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Execute a script only once on 20seconds

Post by mcestoni »

Hola, se puede actualizar emoncms desde la opcion Data Push -> Http
Attachments
Domoticz_Emoncms.jpg
Domoticz_Emoncms.jpg (61.72 KiB) Viewed 866 times
Post Reply

Who is online

Users browsing this forum: No registered users and 0 guests