Page 1 of 1

problem to use modules.lua function like getDeviceName( TTIDX)

Posted: Friday 28 December 2018 18:49
by jluc2808
i tried to get my consumption from my solaredge API and want to display the "real-time" consumption in a virtual device
my script isn't already optimized with json return value (i have to do that next) but my purpose is not on that part.
i'm using modules.lua with the some function but i get for all of them some error :

Code: Select all

	-- maintenant que la valeur de consommation est disponible il faut mettre à  jour la consommation virtuelle 
		  debug = true  -- true pour voir les logs dans la console log Dz ou false pour ne pas les voir

        local devices = {}

        -- tableau a renseigner {'dispositif', puissance, 'compteur'}

        devices[1] = {'solaredge compteur conso', 900, 'consommation solaredge compteur conso'}

        -- fin du tableau
      
        commandArray = {}

                for n,device in pairs(devices) do
                -- domoticz.log(getDeviceName('11'), debugging)   -- get an error message so i comment this line 
                
                TTIDX = '61'   -- IDX of 'solaredge compteur conso' is 61
                energy = round(tonumber(realconsumptionValue, dec))  -- realconsumptionValue est la valeur temps réel en retour de l'API , format text
                domoticz.log(energy, debugging)  -- juste pour m'assurer que la valeur est correctement prise 
                
                -- je suis passé par cette ordre domoticz parce que "commandArray['UpdateDevice'] = TTIDX ..'|0|'.. realconsumptionValue" ne fonctionne pas 
                url = domoticz.settings['Domoticz url'] ..
                        '/json.htm?type=command&param=udevice&idx=' .. TTIDX  .. '&nvalue=' .. realconsumptionValue .. '&svalue=' .. energy
                domoticz.log('Setting temp using openURL ' .. url)    -- log la commande pour m'assurer que c'est bon 
                domoticz.openURL(url)  
                
              --  commandArray['UpdateDevice'] = TTIDX ..'|0|'.. realconsumptionValue    -- mise en commentaire me retourne une erreur 
	      --  commandArray['UpdateDevice'] = otherdevices_idx[device[3]] .. '|0|' .. device[2] .. ';' .. energy -- Mise à jour du compteur (puissance instantanée) ne fonctionne pas non plus error 

    	        end
    	        return commandArray
        
getDeviceName(TTIDX'), but get an error
2018-12-28 18:24:01.488 Status: dzVents: Error (2.4.8): /volume1/@appstore/domoticz/var/scripts/lua/modules.lua:319: bad argument #1 to 'pairs' (table expected, got nil)

when i use commandArray['UpdateDevice'] = otherdevices_idx[device[3]] .. '|0|' .. device[2] .. ';' .. energy
error : attempt to index global 'otherdevices_idx' (a nil value)

i know i'm surely wrong somewhere !!!!
please help

Re: problem to use modules.lua function like getDeviceName( TTIDX)

Posted: Friday 28 December 2018 18:55
by waaren
jluc2808 wrote: Friday 28 December 2018 18:49 i tried to get my consumption from my solaredge API and want to display the "real-time" consumption in a virtual device
my script isn't already optimized with json return value (i have to do that next) but my purpose is not on that part.
i'm using modules.lua with the some function but i get for all of them some error :

i know i'm surely wrong somewhere !!!!
please help
You are mixing domoticz Lua and dzVents.
Please heave a look at the dzVents wiki and the many examples on this forum.

Re: problem to use modules.lua function like getDeviceName( TTIDX)

Posted: Saturday 29 December 2018 0:19
by jluc2808
ok merci pour cette réponse effectivement j'ai mélangé LUA et DzVents , j'ai mis dans le bon ordre et maintenant c'est OK

Code: Select all

if (item.isHTTPResponse) then

        			if (item.statusCode == 200) then
        				if (item.isJSON) then
        				    
        			if (debugging) then	    
        			    domoticz.log('traitement de powerdetail')
        			end
        			temp_data = item.json.powerDetails.meters[1].values[1]
        			if (temp_data.value ~= nil) then 
			            realconsumptionValue = item.json.powerDetails.meters[1].values[1].value
			        end 
    		        if (realconsumptionValue ~= "0") then 
        			    energy = round(tonumber(realconsumptionValue, dec))
        			end
        			-- update consommation instantanée
        			domoticz.devices('solaredge total consommation').updateEnergy(energy)
		end		
		else
           if (debugging) then 
	        	if realconsumptionValue ~= "" then
                    print ("<font color='#f3031d'>".. realconsumptionValue .."</font>")
		        else
		        print ("<font color='#f3031d'>aucune valeur affichable</font>")
		        end
            end
				domoticz.log('There was a problem handling the request', domoticz.LOG_ERROR)
				domoticz.log(item, domoticz.LOG_ERROR)
		    end
	    end