Utility value to dummy percentage
Moderator: leecollings
-
Tarzan737
- Posts: 60
- Joined: Friday 01 June 2018 20:32
- Target OS: Raspberry Pi / ODroid
- Domoticz version:
- Contact:
Utility value to dummy percentage
Hello..
is it possible to convert a value to percent..
if i get a value on my utility sensor from let´s say 0 - 270 but want to see that in percent instead..
like 270 is 100% and 0 is 0
is it any script for that to a dummy sensor? or any solution
is it possible to convert a value to percent..
if i get a value on my utility sensor from let´s say 0 - 270 but want to see that in percent instead..
like 270 is 100% and 0 is 0
is it any script for that to a dummy sensor? or any solution
- felix63
- Posts: 244
- Joined: Monday 07 December 2015 9:30
- Target OS: Raspberry Pi / ODroid
- Domoticz version: 2020.1
- Location: Gouda
- Contact:
Re: Utility value to dummy percentage
First create a virtual sensor of type 'percentage'. Lets say 'percentage'. Then create the following dzvents script to convert the value from 'sensor' 0 - 270 to a percentage value in sensor 'percentage'. Haven't tested the script btw. Might contain errors!
Code: Select all
return {
-- 'active' controls if this entire script is considered or not
active = true, -- set to false to disable this script
-- trigger
-- can be a combination:
on = {
devices = {
-- scripts is executed if the device that was updated matches with one of these triggers
'sensor',
},
},
logging = {
-- level = domoticz.LOG_INFO,
marker = "Converter"
},
-- actual event code
-- in case of a timer event or security event, device == nil
execute = function(domoticz, device)
domoticz.devices('percentage').updatePercentage(domoticz.utils.round((domoticz.devices('Sensor').nValue/270)*100),2)
end
}-
Tarzan737
- Posts: 60
- Joined: Friday 01 June 2018 20:32
- Target OS: Raspberry Pi / ODroid
- Domoticz version:
- Contact:
Re: Utility value to dummy percentage
Thanks!
I couldnt really make it work last night with that script. I just renamed sensor and percentage to the name of my devices, something else to do?
I couldnt really make it work last night with that script. I just renamed sensor and percentage to the name of my devices, something else to do?
- waaren
- Posts: 6028
- Joined: Tuesday 03 January 2017 14:18
- Target OS: Linux
- Domoticz version: Beta
- Location: Netherlands
- Contact:
Re: Utility value to dummy percentage
Not every sensor use nValue to store the measured value. What is the type / subtype of your sensor ? (look at the devices tab)Tarzan737 wrote: Tuesday 19 February 2019 6:20 Thanks!
I couldnt really make it work last night with that script. I just renamed sensor and percentage to the name of my devices, something else to do?
What do you see in the logfile ?
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
-
Tarzan737
- Posts: 60
- Joined: Friday 01 June 2018 20:32
- Target OS: Raspberry Pi / ODroid
- Domoticz version:
- Contact:
Re: Utility value to dummy percentage
it looks like this.. and i use denkovi daenetip4 hardware
- Attachments
-
- Screenshot (17).png (373.66 KiB) Viewed 3516 times
- waaren
- Posts: 6028
- Joined: Tuesday 03 January 2017 14:18
- Target OS: Linux
- Domoticz version: Beta
- Location: Netherlands
- Contact:
Re: Utility value to dummy percentage
In this deviceType the value is stored in the sValue field. Can you test below script ?Tarzan737 wrote: Tuesday 19 February 2019 17:26 it looks like this.. and i use denkovi daenetip4 hardware
Code: Select all
return {
on = {
devices = {
'sensor'
},
},
logging = {
level = domoticz.LOG_INFO,
marker = "Converter"
},
execute = function(dz, item)
local dataFromSensor = item.rawData[1]
local maxValue = 270
local decimals = 2
local percentage = dataFromSensor / maxValue * 100
local roundedPercentage = dz.utils.round(percentage,decimals )
local percentageDevice = dz.devices('percentage')
dz.log("Rounded percentage is " .. roundedPercentage .. "%")
percentageDevice.updatePercentage(roundedPercentage)
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
-
Tarzan737
- Posts: 60
- Joined: Friday 01 June 2018 20:32
- Target OS: Raspberry Pi / ODroid
- Domoticz version:
- Contact:
Re: Utility value to dummy percentage
YEEESSS!! This seems to work!! Thank you very much for help..
if i want to have the opposite.. like value 0 is 100% instead.. because i don´t know how my new sensor works.. (haven`t recieved it)
value 1023 0% and value 0 100%
if i want to have the opposite.. like value 0 is 100% instead.. because i don´t know how my new sensor works.. (haven`t recieved it)
value 1023 0% and value 0 100%
- waaren
- Posts: 6028
- Joined: Tuesday 03 January 2017 14:18
- Target OS: Linux
- Domoticz version: Beta
- Location: Netherlands
- Contact:
Re: Utility value to dummy percentage
set inverted = true in below script should do thatTarzan737 wrote: Tuesday 19 February 2019 21:27 YEEESSS!! This seems to work!! Thank you very much for help..
if i want to have the opposite.. like value 0 is 100% instead.. because i don´t know how my new sensor works.. (haven`t recieved it)
value 1023 0% and value 0 100%
Code: Select all
return {
on = {
devices = {
'sensor'
},
},
logging = {
level = domoticz.LOG_INFO,
marker = "Converter"
},
execute = function(dz, item)
local inverted = false -- if max value of sensor should be reflected in 0% and 0 in 100%
local dataFromSensor = item.rawData[1]
local maxValue = 270
local decimals = 2
local percentage = dataFromSensor / maxValue * 100
if inverted then
percentage = 100 - percentage
end
local roundedPercentage = dz.utils.round(percentage,decimals )
local percentageDevice = dz.devices('percentage')
dz.log("Rounded percentage is " .. roundedPercentage .. "%")
percentageDevice.updatePercentage(roundedPercentage)
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
-
Tarzan737
- Posts: 60
- Joined: Friday 01 June 2018 20:32
- Target OS: Raspberry Pi / ODroid
- Domoticz version:
- Contact:
Re: Utility value to dummy percentage
Thank u very much!! it works fine!!
-
Tarzan737
- Posts: 60
- Joined: Friday 01 June 2018 20:32
- Target OS: Raspberry Pi / ODroid
- Domoticz version:
- Contact:
Re: Utility value to dummy percentage
Hello!!
i noticed that my 0 value not always is 0 when calibrating my sensors, it could be like 137 or something so the percentage will not
show correct.
i tried to add the line localMinvalue = 137 but nu success..
not that easy that i thought
i noticed that my 0 value not always is 0 when calibrating my sensors, it could be like 137 or something so the percentage will not
show correct.
i tried to add the line localMinvalue = 137 but nu success..
not that easy that i thought
- waaren
- Posts: 6028
- Joined: Tuesday 03 January 2017 14:18
- Target OS: Linux
- Domoticz version: Beta
- Location: Netherlands
- Contact:
Re: Utility value to dummy percentage
Could be something like this ? Adjust minValue to what you observeTarzan737 wrote: Wednesday 27 February 2019 21:12 Hello!!
i noticed that my 0 value not always is 0 when calibrating my sensors, it could be like 137 or something so the percentage will not
show correct.
i tried to add the line localMinvalue = 137 but nu success..
not that easy that i thought![]()
Code: Select all
return {
on = {
devices = {
'sensor'
},
},
logging = {
level = domoticz.LOG_INFO,
marker = "Converter"
},
execute = function(dz, item)
local inverted = false -- if max value of sensor should be reflected in 0% and 0 in 100%
local dataFromSensor = item.rawData[1]
local maxValue = 270
local decimals = 2
local minValue = 0
local percentage = ( dataFromSensor - minValue ) / maxValue * 100
if inverted then
percentage = 100 - percentage
end
local roundedPercentage = dz.utils.round(percentage,decimals )
local percentageDevice = dz.devices('percentage')
dz.log("Rounded percentage is " .. roundedPercentage .. "%")
percentageDevice.updatePercentage(roundedPercentage)
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
-
Tarzan737
- Posts: 60
- Joined: Friday 01 June 2018 20:32
- Target OS: Raspberry Pi / ODroid
- Domoticz version:
- Contact:
Re: Utility value to dummy percentage
Yepp!! seems to work! Thanks again
-
Tarzan737
- Posts: 60
- Joined: Friday 01 June 2018 20:32
- Target OS: Raspberry Pi / ODroid
- Domoticz version:
- Contact:
Re: Utility value to dummy percentage
hmm need help again
in my tank level sensor max value is 502 and min value 492
but it does not show correct at all, let´s say my sensor output is 499
with this formula ( dataFromSensor - minValue ) / maxValue * 100
it will take 499-492 = 7 then take 7/502 * 100
and the percentage is not correct..
any idea how to write the code?
in my tank level sensor max value is 502 and min value 492
but it does not show correct at all, let´s say my sensor output is 499
with this formula ( dataFromSensor - minValue ) / maxValue * 100
it will take 499-492 = 7 then take 7/502 * 100
and the percentage is not correct..
any idea how to write the code?
- waaren
- Posts: 6028
- Joined: Tuesday 03 January 2017 14:18
- Target OS: Linux
- Domoticz version: Beta
- Location: Netherlands
- Contact:
Re: Utility value to dummy percentage
Sure but first need to understandTarzan737 wrote: Tuesday 05 March 2019 19:47 in my tank level sensor max value is 502 and min value 492
any idea how to write the code?
So 502 is 100% and 492 = 0% ?
Or do you mean 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
-
Tarzan737
- Posts: 60
- Joined: Friday 01 June 2018 20:32
- Target OS: Raspberry Pi / ODroid
- Domoticz version:
- Contact:
Re: Utility value to dummy percentage
Yepp! Correct. (In this case with tank level)
- waaren
- Posts: 6028
- Joined: Tuesday 03 January 2017 14:18
- Target OS: Linux
- Domoticz version: Beta
- Location: Netherlands
- Contact:
Re: Utility value to dummy percentage
Can you test this ?
Code: Select all
return {
on = {
devices = {
'sensor'
},
},
logging = {
level = domoticz.LOG_INFO,
marker = "Converter"
},
execute = function(dz, item)
local inverted = false -- if max value of sensor should be reflected in 0% and minValue in 100%
local dataFromSensor = item.rawData[1]
local maxValue = 502
local minValue = 492
local decimals = 2
local percentage = ( dataFromSensor - minValue ) / ( maxValue - minValue ) * 100
if inverted then
percentage = 100 - percentage
end
local roundedPercentage = dz.utils.round(percentage,decimals )
local percentageDevice = dz.devices('percentage')
dz.log("Rounded percentage is " .. roundedPercentage .. "%")
percentageDevice.updatePercentage(roundedPercentage)
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
-
Tarzan737
- Posts: 60
- Joined: Friday 01 June 2018 20:32
- Target OS: Raspberry Pi / ODroid
- Domoticz version:
- Contact:
Re: Utility value to dummy percentage
Yes that works as i wish, what should i do without you
thanks again
-
Tarzan737
- Posts: 60
- Joined: Friday 01 June 2018 20:32
- Target OS: Raspberry Pi / ODroid
- Domoticz version:
- Contact:
Re: Utility value to dummy percentage
Hello..
has anything changed with domoticz?
i cant make this code work anymore..
anyone knows why?
i use the same hardware (daenetip4)
has anything changed with domoticz?
i cant make this code work anymore..
anyone knows why?
i use the same hardware (daenetip4)
- waaren
- Posts: 6028
- Joined: Tuesday 03 January 2017 14:18
- Target OS: Linux
- Domoticz version: Beta
- Location: Netherlands
- Contact:
Re: Utility value to dummy percentage
Yes
Please supply some more background. What is your current domoticz version / OS / What do you see in the log / what does not worki cant make this code work anymore..
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
-
Tarzan737
- Posts: 60
- Joined: Friday 01 June 2018 20:32
- Target OS: Raspberry Pi / ODroid
- Domoticz version:
- Contact:
Re: Utility value to dummy percentage
i think i did see now!! in options i had to check the box enable dz vents.. it should be the last version
had som hours just to make domoticz start again
had som hours just to make domoticz start again
Who is online
Users browsing this forum: No registered users and 1 guest