Page 1 of 1

modify the name of a device with Dzvents script

Posted: Tuesday 08 January 2019 18:36
by jluc2808
hello,
i'm using DzVents scripts, i use to set some value with energy, text, or electricity devices (could be other).
i would like to change the label (name) of virtual devices depending of the contents of the scripts.
by exemple:
i'am using 2 virtuals devices to display a % and text to display

Code: Select all

 Day_Pourcent_self_conso = domoticz.utils.round(Day_SelfConsumption_value / Day_Consumption_value * 100, 1)  -- calcul of % with 1 decimal

domoticz.devices(65).updateText(tostring(Day_SelfConsumption_value).." Wh ,"..Day_Pourcent_self_conso.. "% of the day Consumption (" ..Day_Consumption_value..")")  -- display the text within Text device 

domoticz.devices(66).updatePercentage(Day_Pourcent_self_conso)  -- display % within % device 
Image

i would like to change the name of the virtual device to with
domoticz.devices(65).updateName ("xxxx .. Day_Pourcent_self_conso .. " xxx") -- display % within % device name
Image

Re: modify the name of a device with Dzvents script

Posted: Tuesday 08 January 2019 20:18
by waaren
jluc2808 wrote: Tuesday 08 January 2019 18:36 i'm using DzVents scripts
i would like to change the name of the virtual device
Not with a native command but a lot is possible with the openURL command. Check this

Code: Select all

return {
    on          =   {   timer     =   { "every minute"}},
                        
    logging     =   { 
                        level   =  domoticz.LOG_DEBUG,   
                        marker  =  "rename Device" 
                    },    
     
    execute = function(dz)
  
        test = dz.devices(1286)             -- Change to your device idx
        
        clockTime = os.date("%x %X")
        newName= dz.utils.urlEncode("My new name: " ..  clockTime)
        test.updateText(clockTime)
        url = dz.settings["Domoticz url"] .. "/json.htm?type=command&param=renamedevice&idx=" .. test.id .."&name="  .. newName
        dz.openURL( url)
        
    end
}

Re: modify the name of a device with Dzvents script

Posted: Wednesday 09 January 2019 6:51
by jluc2808
waaren wrote: Tuesday 08 January 2019 20:18
jluc2808 wrote: Tuesday 08 January 2019 18:36 i'm using DzVents scripts
i would like to change the name of the virtual device
Not with a native command but a lot is possible with the openURL command. Check this

Code: Select all

return {
    on          =   {   timer     =   { "every minute"}},
                        
    logging     =   { 
                        level   =  domoticz.LOG_DEBUG,   
                        marker  =  "rename Device" 
                    },    
     
    execute = function(dz)
  
        test = dz.devices(1286)             -- Change to your device idx
        
        clockTime = os.date("%x %X")
        newName= dz.utils.urlEncode("My new name: " ..  clockTime)
        test.updateText(clockTime)
        url = dz.settings["Domoticz url"] .. "/json.htm?type=command&param=renamedevice&idx=" .. test.id .."&name="  .. newName
        dz.openURL( url)
        
    end
}
ok thanks , i tried it and that work great , is there somewhere a documentation about all the argument accepted with this method ?

Re: modify the name of a device with Dzvents script

Posted: Wednesday 09 January 2019 8:12
by waaren
jluc2808 wrote: Wednesday 09 January 2019 6:51 is there somewhere a documentation about all the argument accepted with this method ?
Not sure what you mean with this question. dzVents ?, Lua ? domoticz API ?
  • dzVents commands and syntaxis are very well documented in the
    wiki
  • Lua language syntaxis can be found here or here
  • domoticz API / JSON can be found here

Re: modify the name of a device with Dzvents script

Posted: Wednesday 09 January 2019 8:44
by jluc2808
waaren wrote: Wednesday 09 January 2019 8:12
jluc2808 wrote: Wednesday 09 January 2019 6:51 is there somewhere a documentation about all the argument accepted with this method ?
Not sure what you mean with this question. dzVents ?, Lua ? domoticz API ?
  • dzVents commands and syntaxis are very well documented in the
    wiki
  • Lua language syntaxis can be found here or here
  • domoticz API / JSON can be found here
yes it's exactly what i need (the JSON_URL)
thanks a lot