Script from voltage to percentage [Solved]
Moderator: leecollings
-
riekelt3
- Posts: 5
- Joined: Sunday 21 June 2020 14:41
- Target OS: Raspberry Pi / ODroid
- Domoticz version: 2020.2
- Location: Netherlands
- Contact:
Script from voltage to percentage
Hello,
I have rainwater tank in my garden. I have a fibaro smart implant. I added already succesful to domoticz. I can now readout the voltage from the sensor. How can I change the data from voltage to percentage in a script? Please can anyone help me?
regards,
Riekelt
I have rainwater tank in my garden. I have a fibaro smart implant. I added already succesful to domoticz. I can now readout the voltage from the sensor. How can I change the data from voltage to percentage in a script? Please can anyone help me?
regards,
Riekelt
- waaren
- Posts: 6028
- Joined: Tuesday 03 January 2017 14:18
- Target OS: Linux
- Domoticz version: Beta
- Location: Netherlands
- Contact:
Re: Script from voltage to percentage
What is the type and subtype (devices tab) of the current sensor?riekelt3 wrote: Sunday 21 June 2020 15:01 I have rainwater tank in my garden. I have a fibaro smart implant. I added already succesful to domoticz. I can now readout the voltage from the sensor. How can I change the data from voltage to percentage in a script? Please can anyone help me?
What is the min and max voltage?
Should min voltage be 0% and max voltage be 100%?
What should be the frequency to update the virtual percentage sensor? (every change in voltage or every minute or every hour or something else)
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
-
riekelt3
- Posts: 5
- Joined: Sunday 21 June 2020 14:41
- Target OS: Raspberry Pi / ODroid
- Domoticz version: 2020.2
- Location: Netherlands
- Contact:
Re: Script from voltage to percentage
Thanks for the quick reply. I will figure it out and discribe it out.
Regards
Riekelt
Regards
Riekelt
-
riekelt3
- Posts: 5
- Joined: Sunday 21 June 2020 14:41
- Target OS: Raspberry Pi / ODroid
- Domoticz version: 2020.2
- Location: Netherlands
- Contact:
Re: Script from voltage to percentage
The type of the sensor is: general and the subtype: voltage
The min voltage is: 1,45V and the Max: 2,06V
Yes the min voltage should be 0% and the max voltage should be 100%
The frequence should be every change in voltage
Regards
Riekelt
The min voltage is: 1,45V and the Max: 2,06V
Yes the min voltage should be 0% and the max voltage should be 100%
The frequence should be every change in voltage
Regards
Riekelt
- waaren
- Posts: 6028
- Joined: Tuesday 03 January 2017 14:18
- Target OS: Linux
- Domoticz version: Beta
- Location: Netherlands
- Contact:
Re: Script from voltage to percentage
Could be something like
Code: Select all
return
{
on =
{
devices =
{
'waterLevelVoltage' -- change to name of voltage device
}
},
logging =
{
level = domoticz.LOG_DEBUG, -- change to domoticz.LOG_ERROR when script executes without issues
marker = 'watertank level',
},
execute = function(dz, item)
local measuredVoltage = item.voltage
local tankLevelIndicator = dz.devices('waterLevel') -- change to name of percentage device
local minVoltage = 1.45
local maxVoltage = 2,06
local function guardPercentage( percentage )
if percentage > 0.05 and percentage <= 100 then return percentage end
dz.log('Unexpected voltage (' .. percentage .. ')', dz.LOG_ERROR)
if percentage > 100 then return 100 else return 0 end
end
local levelPercentage = dz.utils.round( guardPercentage ( ( measuredVoltage - minVoltage ) * ( 100 / ( maxVoltage - minVoltage ) ) ) ,1 )
dz.log('Percentage = ' .. levelPercentage, dz.LOG_DEBUG)
tankLevelIndicator.updatePercentage(levelPercentage)
end
}Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
-
riekelt3
- Posts: 5
- Joined: Sunday 21 June 2020 14:41
- Target OS: Raspberry Pi / ODroid
- Domoticz version: 2020.2
- Location: Netherlands
- Contact:
Re: Script from voltage to percentage
The script is working. I am very happy with this. Only when I see the voltage and the percentage it is for 2 seconds. And than the voltage and percentage go to 0. Untill the next voltage is coming from the sensor.
- waaren
- Posts: 6028
- Joined: Tuesday 03 January 2017 14:18
- Target OS: Linux
- Domoticz version: Beta
- Location: Netherlands
- Contact:
Re: Script from voltage to percentage
if domoticz receive a volt update it will update the volt sensor. Not much you can do about that. The percentage sensor is controlled by dzVents.riekelt3 wrote: Friday 26 June 2020 20:06 The script is working. I am very happy with this. Only when I see the voltage and the percentage it is for 2 seconds. And than the voltage and percentage go to 0. Untill the next voltage is coming from the sensor.
You could change the guardPercentage function to
Code: Select all
local function guardPercentage( percentage )
if percentage >= 0.1 and percentage <= 100 then return percentage end
dz.log('Unexpected voltage (' .. percentage .. ')', dz.LOG_DEBUG)
if percentage > 100 then
return 100
else
return tankLevelIndicator.percentage
end
end
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
-
riekelt3
- Posts: 5
- Joined: Sunday 21 June 2020 14:41
- Target OS: Raspberry Pi / ODroid
- Domoticz version: 2020.2
- Location: Netherlands
- Contact:
Re: Script from voltage to percentage [Solved]
It's working now for 100%. Thank you for the support. I am very happy with this.
-
heistje
- Posts: 23
- Joined: Saturday 21 January 2017 13:42
- Target OS: Raspberry Pi / ODroid
- Domoticz version: 2023.2
- Location: Belgium
- Contact:
Re: Script from voltage to percentage
I also used this script for a my garden watertank, not with a fibaro smart implant but with a Water Level Sensor I bought at Aliexpress: https://www.aliexpress.com/item/4000098 ... c4dO2kw75)
and
a ETH8020 (analog input 0-5VDC)
Would like to thank you guys! Thanks to this script it works like a charm!
and
a ETH8020 (analog input 0-5VDC)
Would like to thank you guys! Thanks to this script it works like a charm!
Bullseye on RPI 4
Aeotec Z-Wave Plus Z-Stick Gen5
Zwave-JS-UI
RFXtrx433E
Eth8020
P1 USB
Shellys
ESP8266
Aeotec Z-Wave Plus Z-Stick Gen5
Zwave-JS-UI
RFXtrx433E
Eth8020
P1 USB
Shellys
ESP8266
-
Drdre
- Posts: 4
- Joined: Tuesday 31 March 2015 21:11
- Target OS: Raspberry Pi / ODroid
- Domoticz version:
- Contact:
Re: Script from voltage to percentage
I also need a script but then from voltage (0-5) to windspeed km/h (0-100).
Sombody can help me with this script?
Sombody can help me with this script?
- waltervl
- Posts: 6683
- Joined: Monday 28 January 2019 18:48
- Target OS: Linux
- Domoticz version: 2025.1
- Location: NL
- Contact:
Re: Script from voltage to percentage
You can use the script above but make some modifications.Drdre wrote: Friday 18 February 2022 14:48 I also need a script but then from voltage (0-5) to windspeed km/h (0-100).
Sombody can help me with this script?
But what is your formula to go from voltage to windspeed?
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
- waltervl
- Posts: 6683
- Joined: Monday 28 January 2019 18:48
- Target OS: Linux
- Domoticz version: 2025.1
- Location: NL
- Contact:
Re: Script from voltage to percentage
Assuming 0 volt = 0 kmh and 5 volt = 100 kmh so a factor 20:
formula kmh = V*20
NOT TESTED!!! Could contain Error!!!
formula kmh = V*20
NOT TESTED!!! Could contain Error!!!
Code: Select all
return
{
on =
{
devices =
{
'windspeedvoltage' -- change to name of voltage device
}
},
logging =
{
level = domoticz.LOG_DEBUG, -- change to domoticz.LOG_ERROR when script executes without issues
marker = 'windspeed',
},
execute = function(dz, item)
local measuredVoltage = item.voltage
local WindspeedDevice = dz.devices('windspeed') -- change to name of Custom Sensor for windspeed.
local windspeed = dz.utils.round( measuredVoltage * 20 ,1 )
dz.log('Wind Speed = ' .. windspeed, dz.LOG_DEBUG)
WindspeedDevice.updateCustomSensor(windspeed)
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
-
Drdre
- Posts: 4
- Joined: Tuesday 31 March 2015 21:11
- Target OS: Raspberry Pi / ODroid
- Domoticz version:
- Contact:
Re: Script from voltage to percentage
It's working thanks!!!!!
Who is online
Users browsing this forum: No registered users and 1 guest