Create a Voltage sensor from utility to dummy

Moderator: leecollings

Tarzan737
Posts: 60
Joined: Friday 01 June 2018 20:32
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Create a Voltage sensor from utility to dummy

Post 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?
User avatar
waltervl
Posts: 5859
Joined: Monday 28 January 2019 18:48
Target OS: Linux
Domoticz version: 2024.7
Location: NL
Contact:

Re: Create a Voltage sensor from utility to dummy

Post by waltervl »

Here you have an example of something similar https://domoticz.com/forum/viewtopic.php?t=33414
Domoticz running on Udoo X86 (on Ubuntu)
Devices/plugins: ZigbeeforDomoticz (with Xiaomi, Ikea, Tuya devices), Nefit Easy, Midea Airco, Omnik Solar, Goodwe Solar
Tarzan737
Posts: 60
Joined: Friday 01 June 2018 20:32
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Create a Voltage sensor from utility to dummy

Post 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
User avatar
waltervl
Posts: 5859
Joined: Monday 28 January 2019 18:48
Target OS: Linux
Domoticz version: 2024.7
Location: NL
Contact:

Re: Create a Voltage sensor from utility to dummy

Post 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.
Domoticz running on Udoo X86 (on Ubuntu)
Devices/plugins: ZigbeeforDomoticz (with Xiaomi, Ikea, Tuya devices), Nefit Easy, Midea Airco, Omnik Solar, Goodwe Solar
Tarzan737
Posts: 60
Joined: Friday 01 June 2018 20:32
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Create a Voltage sensor from utility to dummy

Post 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 :)
Tarzan737
Posts: 60
Joined: Friday 01 June 2018 20:32
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Create a Voltage sensor from utility to dummy

Post 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
}
User avatar
waltervl
Posts: 5859
Joined: Monday 28 January 2019 18:48
Target OS: Linux
Domoticz version: 2024.7
Location: NL
Contact:

Re: Create a Voltage sensor from utility to dummy

Post 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).
Domoticz running on Udoo X86 (on Ubuntu)
Devices/plugins: ZigbeeforDomoticz (with Xiaomi, Ikea, Tuya devices), Nefit Easy, Midea Airco, Omnik Solar, Goodwe Solar
Tarzan737
Posts: 60
Joined: Friday 01 June 2018 20:32
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Create a Voltage sensor from utility to dummy

Post 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..
User avatar
waltervl
Posts: 5859
Joined: Monday 28 January 2019 18:48
Target OS: Linux
Domoticz version: 2024.7
Location: NL
Contact:

Re: Create a Voltage sensor from utility to dummy

Post by waltervl »

Here are other scripts that will need some small changes for your use case: viewtopic.php?t=33116
Domoticz running on Udoo X86 (on Ubuntu)
Devices/plugins: ZigbeeforDomoticz (with Xiaomi, Ikea, Tuya devices), Nefit Easy, Midea Airco, Omnik Solar, Goodwe Solar
BartSr
Posts: 395
Joined: Sunday 03 July 2016 16:16
Target OS: Raspberry Pi / ODroid
Domoticz version: V2024.7
Location: Netherlands
Contact:

Re: Create a Voltage sensor from utility to dummy

Post 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.
Raspberry pi 3b
Arduino
KAKU
RfxCom
Zwave2MQTT
OTGW
Chinese sensors temp (Dallas),movement
Tasmota
Esp8266 / 32 espeasy
Zigbee2MQTT
Tarzan737
Posts: 60
Joined: Friday 01 June 2018 20:32
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Create a Voltage sensor from utility to dummy

Post 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
User avatar
waltervl
Posts: 5859
Joined: Monday 28 January 2019 18:48
Target OS: Linux
Domoticz version: 2024.7
Location: NL
Contact:

Re: Create a Voltage sensor from utility to dummy

Post 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.
Domoticz running on Udoo X86 (on Ubuntu)
Devices/plugins: ZigbeeforDomoticz (with Xiaomi, Ikea, Tuya devices), Nefit Easy, Midea Airco, Omnik Solar, Goodwe Solar
Tarzan737
Posts: 60
Joined: Friday 01 June 2018 20:32
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Create a Voltage sensor from utility to dummy

Post 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
}
User avatar
waltervl
Posts: 5859
Joined: Monday 28 January 2019 18:48
Target OS: Linux
Domoticz version: 2024.7
Location: NL
Contact:

Re: Create a Voltage sensor from utility to dummy

Post by waltervl »

double
Last edited by waltervl on Thursday 12 October 2023 9:44, edited 1 time in total.
Domoticz running on Udoo X86 (on Ubuntu)
Devices/plugins: ZigbeeforDomoticz (with Xiaomi, Ikea, Tuya devices), Nefit Easy, Midea Airco, Omnik Solar, Goodwe Solar
User avatar
waltervl
Posts: 5859
Joined: Monday 28 January 2019 18:48
Target OS: Linux
Domoticz version: 2024.7
Location: NL
Contact:

Re: Create a Voltage sensor from utility to dummy

Post 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
Domoticz running on Udoo X86 (on Ubuntu)
Devices/plugins: ZigbeeforDomoticz (with Xiaomi, Ikea, Tuya devices), Nefit Easy, Midea Airco, Omnik Solar, Goodwe Solar
Tarzan737
Posts: 60
Joined: Friday 01 June 2018 20:32
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Create a Voltage sensor from utility to dummy

Post 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..
User avatar
waltervl
Posts: 5859
Joined: Monday 28 January 2019 18:48
Target OS: Linux
Domoticz version: 2024.7
Location: NL
Contact:

Re: Create a Voltage sensor from utility to dummy

Post 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.
Domoticz running on Udoo X86 (on Ubuntu)
Devices/plugins: ZigbeeforDomoticz (with Xiaomi, Ikea, Tuya devices), Nefit Easy, Midea Airco, Omnik Solar, Goodwe Solar
Tarzan737
Posts: 60
Joined: Friday 01 June 2018 20:32
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Create a Voltage sensor from utility to dummy

Post by Tarzan737 »

hello..

i did try that to.. but i get unable to compare number with string in that line in the log..
User avatar
waltervl
Posts: 5859
Joined: Monday 28 January 2019 18:48
Target OS: Linux
Domoticz version: 2024.7
Location: NL
Contact:

Re: Create a Voltage sensor from utility to dummy

Post 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)
Domoticz running on Udoo X86 (on Ubuntu)
Devices/plugins: ZigbeeforDomoticz (with Xiaomi, Ikea, Tuya devices), Nefit Easy, Midea Airco, Omnik Solar, Goodwe Solar
Tarzan737
Posts: 60
Joined: Friday 01 June 2018 20:32
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Create a Voltage sensor from utility to dummy

Post 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
}
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest