Create a Voltage sensor from utility to dummy
Moderator: leecollings
- 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
What error exactly do you get and on what line in the code?
Domoticz running on Udoo X86 (on Ubuntu)
Devices/plugins: ZigbeeforDomoticz (with Xiaomi, Ikea, Tuya devices), Nefit Easy, Midea Airco, Omnik Solar, Goodwe Solar
Devices/plugins: ZigbeeforDomoticz (with Xiaomi, Ikea, Tuya devices), Nefit Easy, Midea Airco, Omnik Solar, Goodwe Solar
-
- 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
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
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
-
- 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
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)
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
}
- 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
What do you want to achieve with
measuredVoltage == 500-510
As I think it checkes for
measuredVoltage == -10
Also you can change it into
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
Domoticz running on Udoo X86 (on Ubuntu)
Devices/plugins: ZigbeeforDomoticz (with Xiaomi, Ikea, Tuya devices), Nefit Easy, Midea Airco, Omnik Solar, Goodwe Solar
Devices/plugins: ZigbeeforDomoticz (with Xiaomi, Ikea, Tuya devices), Nefit Easy, Midea Airco, Omnik Solar, Goodwe Solar
-
- 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
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
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
- Attachments
-
- domoticz.jpg (160.96 KiB) Viewed 1028 times
- 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
You better make it a formula like if 540 is 27 Volt and 300 is 23
But perhaps find better formula on real values and bigger range (10V - 30V)
Code: Select all
Voltage = dz.utils.round(((measuredVoltage-299)/60 + 23) , 1)
Domoticz running on Udoo X86 (on Ubuntu)
Devices/plugins: ZigbeeforDomoticz (with Xiaomi, Ikea, Tuya devices), Nefit Easy, Midea Airco, Omnik Solar, Goodwe Solar
Devices/plugins: ZigbeeforDomoticz (with Xiaomi, Ikea, Tuya devices), Nefit Easy, Midea Airco, Omnik Solar, Goodwe Solar
-
- 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
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!!
edit.. ahh i realized now (Early at morning)
Thank you!!
- 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
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:
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)
Domoticz running on Udoo X86 (on Ubuntu)
Devices/plugins: ZigbeeforDomoticz (with Xiaomi, Ikea, Tuya devices), Nefit Easy, Midea Airco, Omnik Solar, Goodwe Solar
Devices/plugins: ZigbeeforDomoticz (with Xiaomi, Ikea, Tuya devices), Nefit Easy, Midea Airco, Omnik Solar, Goodwe Solar
-
- 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
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!!
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!!
- 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
No that is not possible.
Domoticz running on Udoo X86 (on Ubuntu)
Devices/plugins: ZigbeeforDomoticz (with Xiaomi, Ikea, Tuya devices), Nefit Easy, Midea Airco, Omnik Solar, Goodwe Solar
Devices/plugins: ZigbeeforDomoticz (with Xiaomi, Ikea, Tuya devices), Nefit Easy, Midea Airco, Omnik Solar, Goodwe Solar
Who is online
Users browsing this forum: No registered users and 1 guest