Page 1 of 2

Create a Voltage sensor from utility to dummy

Posted: Wednesday 04 October 2023 18:16
by Tarzan737
Hello.. i need to create a (Dummy) voltage sensor from utility sensor to correct value

lets say i get a value on the utility sensor of 120 (or whatever it is) and send that to dummy sensor as 23V and value 121 (or whatever) as 23.5v
and so on...

someone that can help me with a script?

Re: Create a Voltage sensor from utility to dummy

Posted: Wednesday 04 October 2023 21:25
by waltervl
Here you have an example of something similar https://domoticz.com/forum/viewtopic.php?t=33414

Re: Create a Voltage sensor from utility to dummy

Posted: Wednesday 04 October 2023 21:41
by Tarzan737
hi.. thanks..

something similar.. but i dont want 120 to be 120v or 0 (value of utility) to be 0 V


im going to measure a battery voltage range of like 22v to 27v dc..

lets say utility sensor say 120 and that is the same as 22v and 240 (ut sensor) 27V

Re: Create a Voltage sensor from utility to dummy

Posted: Wednesday 04 October 2023 21:58
by waltervl
With dzvents scripting you can convert values as long as you have a formula.

And if you use some kind of self made sensor there are perhaps possibilities to already have the sensor sending real values.

Re: Create a Voltage sensor from utility to dummy

Posted: Wednesday 04 October 2023 22:12
by Tarzan737
im using denkovi hardware but as i wrote i just get a X value that corresponds to Y volt

so it is a script im looking for to implement/Correct the values from utility sensor to a dummy in volts

its the script and formula i want :)

Re: Create a Voltage sensor from utility to dummy

Posted: Wednesday 04 October 2023 22:15
by Tarzan737
I have this script for a percentage sensor that will work very good but it would be nice to show actually volts instead..

Code: Select all

  return {
     on = {
                devices =   {
                                'Tank'
                            },
        },
   
   logging = {
                level = domoticz.LOG_INFO,
                marker = "Converter"
             },    
    
    execute = function(dz, item)
        local inverted              = true          -- if max value of sensor should be reflected in 0% and minValue in 100% 
        local dataFromAin8        = item.rawData[1]
        local maxValue              = 194
        local minValue              = 44
        local decimals              = 2 
        local percentage            = ( dataFromAin8 - minValue ) / ( maxValue - minValue ) * 100
     
          
        if inverted then 
               percentage = 100 - percentage 
        end
          
        local roundedPercentage     = dz.utils.round(percentage,decimals )
        local percentageDevice      = dz.devices('Vatten')
        
        dz.log("Rounded percentage is " ..  roundedPercentage .. "%")
        percentageDevice.updatePercentage(roundedPercentage)
        
     end
}

Re: Create a Voltage sensor from utility to dummy

Posted: Wednesday 04 October 2023 22:27
by waltervl
Then you have to create a dummy voltage sensor and rewrite the script so it updates this voltage sensor with the correct values.
Check the Dzvents documentation how to update a voltage sensor. https://www.domoticz.com/wiki/DzVents:_ ... ng#Voltage

For using a formula search Google for Lua examples (dzvents is a layer over the programming language Lua) for example https://www.lua.org/pil/3.1.html#:~:tex ... entiation).

Re: Create a Voltage sensor from utility to dummy

Posted: Thursday 05 October 2023 16:48
by Tarzan737
Thanks.. but my level of knowledge is to edit values in finnished scrips, i dont think i can manage to make my own script..

I was hoping someone else had a similar setup..

Re: Create a Voltage sensor from utility to dummy

Posted: Thursday 05 October 2023 16:56
by waltervl
Here are other scripts that will need some small changes for your use case: viewtopic.php?t=33116

Re: Create a Voltage sensor from utility to dummy

Posted: Thursday 05 October 2023 19:55
by BartSr
@Tarzan
Try learning dzVents. Yes... in the beginning it's very difficult but by figuring out excisting scripts you definitly get the skills. Then, if your self written script does not do what you want many people around here are helpfull for you.
Just begin with a very simple script.

Re: Create a Voltage sensor from utility to dummy

Posted: Sunday 08 October 2023 15:12
by Tarzan737
i have tried some days now to edit scrips and so on.. i cant get it to work..

can someone give me an exampe of a script just to copy the same info from a utility sensor
to a dummy voltage sensor..

i tried something like this (plus a lot of others with no result)

Code: Select all

return
{
    on =
    {
        devices =
        {
            'Batt'      -- change to name of voltage device
        }
    },

    logging =
    {
        level = domoticz.LOG_DEBUG, -- change to domoticz.LOG_ERROR when script executes without issues
        marker = 'voltage',
    },

    execute = function(dz, item)
        local Sensor        = item.rawData[1]
        local voltageDevice = dz.devices('Test') -- change to name of Custom Sensor for windspeed.
    
       
       local voltage = dataFromAin8 
       

    end
}
lets say the utility sensor have the name of Batt and the dummy voltage sensor is Test

Re: Create a Voltage sensor from utility to dummy

Posted: Sunday 08 October 2023 23:26
by waltervl
I do not know what you took as a base but the script from this topic should be a good base for you. viewtopic.php?p=287065#p287065

Check the Dzvents documentation for the specific commands to read and update your device. They are different for each device type.

Re: Create a Voltage sensor from utility to dummy

Posted: Monday 09 October 2023 21:21
by Tarzan737
ok so i tried to use that as base and now my dummy device is updating in time and i can se in log that its reading values from
my device as well.. but no values are updating in custom volt device still 0v

this is how the script looks like now..

Code: Select all

return
{
    on =
    {
        devices =
        {
            'Batt'      -- change to name of voltage device
        }
    },

    logging =
    {
        level = domoticz.LOG_DEBUG, -- change to domoticz.LOG_ERROR when script executes without issues
        marker = 'volt',
    },

    execute = function(dz, item)
        local VoltageDevice = dz.devices('Volt') -- change to name of Custom Sensor for windspeed.
        local decimals = 2
        local measuredVoltage = item.rawData[1]
    
        
        local Voltage = dz.utils.round(measuredVoltage)
        
    
    
    
        local roundedVoltage     = dz.utils.round(measuredVoltage,decimals ) 
        
        
        
        
    
     

        dz.log('Voltage = ' .. Voltage, dz.LOG_DEBUG)
        
      VoltageDevice.updateVoltage(voltage)

    end
}

Re: Create a Voltage sensor from utility to dummy

Posted: Monday 09 October 2023 22:12
by waltervl
double

Re: Create a Voltage sensor from utility to dummy

Posted: Monday 09 October 2023 22:17
by waltervl
Dzvents is case sensitive so voltage should be Voltage in

Code: Select all

VoltageDevice.updateVoltage(Voltage)
And

Code: Select all

local measuredVoltage = item.voltage

Re: Create a Voltage sensor from utility to dummy

Posted: Monday 09 October 2023 22:31
by Tarzan737
ohh so stupid i feel now.. i have been watching this so many times but not really good in this.. but thanks (very much) it is working now..

now i want something like

Code: Select all

 if measuredVoltage > 500 then voltage 27 end 
if u know what i mean?

so i can convert different values to correct voltage.. but i cant really find out how to write.. not even with dzwents manual..

Re: Create a Voltage sensor from utility to dummy

Posted: Monday 09 October 2023 22:45
by waltervl
I believe this will work

Code: Select all

 if measuredVoltage > 500 then Voltage=27 end 
This is all standard Lua so search Google with your question for if then Lua and you will find examples.

I see you have measuredvoltage, roundedvoltage and voltage. That also seems 1 too many.

Re: Create a Voltage sensor from utility to dummy

Posted: Tuesday 10 October 2023 16:22
by Tarzan737
hello..

i did try that to.. but i get unable to compare number with string in that line in the log..

Re: Create a Voltage sensor from utility to dummy

Posted: Tuesday 10 October 2023 17:47
by waltervl
Then you need to convert the number into a string for logging eg

Code: Select all

dz.log('Voltage = ' .. tostring(Voltage), dz.LOG_DEBUG)

Re: Create a Voltage sensor from utility to dummy

Posted: Tuesday 10 October 2023 19:12
by Tarzan737
ok. so probably its other stuff i need to change now with string values? since i get the same error in log.. Dont i think i manage to do this
right now..

anyway this is the last code i have if someone see anything obvious that i do wrong

Code: Select all

return
{
    on =
    {
        devices =
        {
            'Batt'      -- change to name of voltage device
        }
    },

    logging =
    {
        level = domoticz.LOG_DEBUG, -- change to domoticz.LOG_ERROR when script executes without issues
        marker = 'volt',
    },

    execute = function(dz, item)
        local VoltageDevice = dz.devices('Volt') -- change to name of Custom Sensor for voltage.
        local decimals = 2
        local measuredVoltage = item.rawData[1]
    
        
        local Voltage = measuredVoltage
        
        if measuredVoltage > 450 then Voltage=27 end
       
       
        dz.log('Voltage = ' .. tostring(Voltage), dz.LOG_DEBUG) 
        
       VoltageDevice.updateVoltage(Voltage)

    end
}