Page 2 of 2

Re: Create a Voltage sensor from utility to dummy

Posted: Tuesday 10 October 2023 21:58
by waltervl
What error exactly do you get and on what line in the code?

Re: Create a Voltage sensor from utility to dummy

Posted: Wednesday 11 October 2023 17:45
by Tarzan737
hi! i get this in the log with latest script

2023-10-11 17:44:08.545 Error: dzVents: Error: (3.1.8) volt: An error occurred when calling event handler Test
2023-10-11 17:44:08.545 Error: dzVents: Error: (3.1.8) volt: ...e/pi/domoticz/scripts/dzVents/generated_scripts/Test.lua:25: attempt to compare number with string

Re: Create a Voltage sensor from utility to dummy

Posted: Wednesday 11 October 2023 17:52
by Tarzan737
or is it possible to write a code like this? numbers between instead of > ?

when using this code the log is clean and updating time in voltage sensor but only the value from batt (not correcting value to volt)

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 measuredVoltage = item.rawData[1]
    
        
        local Voltage = measuredVoltage
        
        if measuredVoltage == 500-510 then Voltage=27 end
        
       
       
       
        dz.log('Voltage = ' .. tostring(Voltage), dz.LOG_DEBUG) 
        
       VoltageDevice.updateVoltage(Voltage)

    end
}

Re: Create a Voltage sensor from utility to dummy

Posted: Wednesday 11 October 2023 22:41
by waltervl
What do you want to achieve with
measuredVoltage == 500-510
As I think it checkes for
measuredVoltage == -10

Also you can change it into

Code: Select all

If Voltage == 500 then Voltage=27 end

Re: Create a Voltage sensor from utility to dummy

Posted: Wednesday 11 October 2023 23:00
by Tarzan737
ok then it is not what i want..

my final goal is this..

my device Batt has a value (in real world it is a 24v battery charging from 23-27 volts)
and this gives a value from lets say 300 to 520 something from (hardware Denkovi to domotics)

i want to create a dummy volt sensor that translates values to volt..

like Batt value 300-315 is 23Volt, Batt 315-320 is 23.5 volt and so on..

Batt is a custom sensor
Volt is a dummy voltage sensor

Re: Create a Voltage sensor from utility to dummy

Posted: Wednesday 11 October 2023 23:41
by waltervl
You better make it a formula like if 540 is 27 Volt and 300 is 23

Code: Select all

Voltage = dz.utils.round(((measuredVoltage-299)/60 + 23) , 1) 
But perhaps find better formula on real values and bigger range (10V - 30V)

Re: Create a Voltage sensor from utility to dummy

Posted: Thursday 12 October 2023 5:55
by Tarzan737
Yes this works.. Thanks, can i ask what the 60 do in the formula? how could you findout 60?



edit.. ahh i realized now (Early at morning)

Thank you!!

Re: Create a Voltage sensor from utility to dummy

Posted: Thursday 12 October 2023 9:05
by waltervl
Great!
I would expect the batt sensor value is lineair to real voltage. so 0 = 0V and 540 = 27 Volt. This would simplify the formula a lot:

Code: Select all

Voltage = dz.utils.round(measuredVoltage/20 , 1)

Re: Create a Voltage sensor from utility to dummy

Posted: Thursday 12 October 2023 18:28
by Tarzan737
yes.. i would think that to.. the batt is connected to a device that shut off the load at 23V that is why i wanted it as value 0V
but mayby i should use the entire range as you write 0 = 0V anyway

im very happy about the code you helped me with as it is!

But i have another overkill question (not that important)

if it is possible that the values changes in color in voltage device?

like 23 V is red and => 24V is Green?

if not possible thanks anyway again!!

Re: Create a Voltage sensor from utility to dummy

Posted: Thursday 12 October 2023 18:55
by waltervl
No that is not possible.