Analog measurement

Easy to use, 100% Lua-based event scripting framework.
Post Reply
Knibor
Posts: 50
Joined: Sunday 20 May 2018 12:56
Target OS: OS X
Domoticz version: Beta
Contact:

Analog measurement

Post by Knibor » Saturday 27 October 2018 9:46

Hi,

I have a question how to establish the following with dzVents.

I have

Switch with IDX=1
Voltage indicator with IDX=2
Voltage indicator with IDX=3

When Switch with IDX=1 is "ON" then copy the measured voltage from IDX=2 to the voltage indicator with IDX=3

Can some help me with this?

Thanks

User avatar
waaren
Posts: 1358
Joined: Tuesday 03 January 2017 15:18
Target OS: Raspberry Pi
Domoticz version: Beta
Location: Netherlands
Contact:

Re: Analog measurement

Post by waaren » Saturday 27 October 2018 10:49

Knibor wrote:
Saturday 27 October 2018 9:46
When Switch with IDX=1 is "ON" then copy the measured voltage from IDX=2 to the voltage indicator with IDX=3
Do you want to copy the value from 2 to 3 only when the switch state change from Off to On or do you want to copy from 2 to 3 every x minutes for as long as the switch state is On ?
Raspberry (debian stretch via berryboot on Synology DS916+) , Domoticz (almost) latest Beta, , dzVents 2.6, RFLink, RFXtrx433e, P1, Youless, Harmony, Hue, Yeelight, Xiaomi, HomeWizard, Zwave, Amazon echo

Knibor
Posts: 50
Joined: Sunday 20 May 2018 12:56
Target OS: OS X
Domoticz version: Beta
Contact:

Re: Analog measurement

Post by Knibor » Saturday 27 October 2018 12:42

Hi,

Thanks for you reply, I want copy the value from 2 to 3 every x seconds for as long as the switch state is On ?
And when the Switch is Off the last On value keeps in IDX 3

User avatar
waaren
Posts: 1358
Joined: Tuesday 03 January 2017 15:18
Target OS: Raspberry Pi
Domoticz version: Beta
Location: Netherlands
Contact:

Re: Analog measurement

Post by waaren » Saturday 27 October 2018 14:31

Knibor wrote:
Saturday 27 October 2018 12:42
I want copy the value from 2 to 3 every x seconds for as long as the switch state is On ?
And when the Switch is Off the last On value keeps in IDX 3
This script is triggered on any update to the voltage sensor with IDX 2 and copy the voltage value to (virtual) voltage sensor with IDX 3 when Switch is On and values in the voltage sensors are not already equal.

Code: Select all

-- voltageCopy

return {
    on = { devices =  { 2 }},                                         -- Master voltage sensor
    
        logging =   {   level   =   domoticz.LOG_DEBUG,               -- commment these 2 lines when script execute without any issues
                        marker  =   "voltageCopy" },

    execute = function(dz, item)                                      -- item is the Master voltage sensot 
        local slaveVoltageSensor  = dz.devices(3)
        local voltageCopySwitch   = dz.devices(1)
        if voltageCopySwitch.state == "On" then
            if slaveVoltageSensor.voltage ~= item.voltage then 
                dz.log("Script is triggered by " .. item.name .. "; new voltage (" .. item.voltage .. ") will be copied to " .. slave.name,dz.LOG_DEBUG)
                slaveVoltageSensor.updateVoltage(item.voltage)        - the actual copy 
            else
                dz.log("Script is triggered by " .. item.name .. "; voltage (" .. item.voltage .. ") will NOT be copied to " .. slave.name .. "(voltages are equal)",dz.LOG_DEBUG)
            end
        else
            dz.log("Script is triggered by " .. item.name .. "; voltage (" .. item.voltage .. ") will NOT be copied to " .. slave.name .. "(control switch is Off)",dz.LOG_DEBUG)
        end    
    end
}
Raspberry (debian stretch via berryboot on Synology DS916+) , Domoticz (almost) latest Beta, , dzVents 2.6, RFLink, RFXtrx433e, P1, Youless, Harmony, Hue, Yeelight, Xiaomi, HomeWizard, Zwave, Amazon echo

Knibor
Posts: 50
Joined: Sunday 20 May 2018 12:56
Target OS: OS X
Domoticz version: Beta
Contact:

Re: Analog measurement

Post by Knibor » Saturday 27 October 2018 16:27

Hi, thanks for the code.
I tried this code with the actual IDX from my Domoticz system, but until now no succes.
Domoticz says there is an Error in line ...slaveVoltageSensor.updateVoltage(item.voltage) - the actual copy
I tried to delete this part. The error was gone but, I don't know should i delete this part? When I delete this part, still no succes.

Here is my actual code
Attachments
Schermafbeelding 2018-10-27 om 16.26.57.png
Schermafbeelding 2018-10-27 om 16.26.57.png (320.7 KiB) Viewed 180 times

User avatar
waaren
Posts: 1358
Joined: Tuesday 03 January 2017 15:18
Target OS: Raspberry Pi
Domoticz version: Beta
Location: Netherlands
Contact:

Re: Analog measurement

Post by waaren » Saturday 27 October 2018 19:17

Knibor wrote:
Saturday 27 October 2018 16:27
Domoticz says there is an Error in line ...slaveVoltageSensor.updateVoltage(item.voltage) - the actual copy
I tried to delete this part. The error was gone but, I don't know should i delete this part? When I delete this part, still no succes.
the part "- the actual copy" is missing 1 "-"
the line should have been

Code: Select all

slaveVoltageSensor.updateVoltage(item.voltage)        -- the actual copy 
-- the actual copy is only a comment to explain what is happening in the script.
To be complete I post the corrected script.

Code: Select all

-- voltageCopy

return {
    on = { devices =  { 2 }},                                         -- Master voltage sensor
    
        logging =   {   level   =   domoticz.LOG_DEBUG,               -- commment these 2 lines when script execute without any issues
                        marker  =   "voltageCopy" },

    execute = function(dz, item)                                      -- item is the Master voltage sensot 
        local slaveVoltageSensor  = dz.devices(3)
        local voltageCopySwitch   = dz.devices(1)
        if voltageCopySwitch.state == "On" then
            if slaveVoltageSensor.voltage ~= item.voltage then 
                dz.log("Script is triggered by " .. item.name .. "; new voltage (" .. item.voltage .. ") will be copied to " .. slave.name,dz.LOG_DEBUG)
                slaveVoltageSensor.updateVoltage(item.voltage)        -- the actual copy 
            else
                dz.log("Script is triggered by " .. item.name .. "; voltage (" .. item.voltage .. ") will NOT be copied to " .. slave.name .. "(voltages are equal)",dz.LOG_DEBUG)
            end
        else
            dz.log("Script is triggered by " .. item.name .. "; voltage (" .. item.voltage .. ") will NOT be copied to " .. slave.name .. "(control switch is Off)",dz.LOG_DEBUG)
        end    
    end
}
Raspberry (debian stretch via berryboot on Synology DS916+) , Domoticz (almost) latest Beta, , dzVents 2.6, RFLink, RFXtrx433e, P1, Youless, Harmony, Hue, Yeelight, Xiaomi, HomeWizard, Zwave, Amazon echo

Knibor
Posts: 50
Joined: Sunday 20 May 2018 12:56
Target OS: OS X
Domoticz version: Beta
Contact:

Re: Analog measurement

Post by Knibor » Saturday 27 October 2018 20:14

Hi,
I tried this latest code with a fresh installed Domoticz, so only this code and the new IDX
IDX 14 is the master voltage sensor, were I can read now the value 80.
IDX 13 is the slave sensor, and I read now the value "0".
IDX 15 is the voltage Switch and I with it on and off serval times. Also tried when the switch is on change the value off IDX 14 master voltage.
But no copy from IDX 14 to IDX15.

Do I something wrong?
Here is my log
Attachments
Schermafbeelding 2018-10-27 om 20.12.55.png
Schermafbeelding 2018-10-27 om 20.12.55.png (34.94 KiB) Viewed 152 times
Schermafbeelding 2018-10-27 om 20.12.27.png
Schermafbeelding 2018-10-27 om 20.12.27.png (62.5 KiB) Viewed 152 times
Schermafbeelding 2018-10-27 om 20.11.45.png
Schermafbeelding 2018-10-27 om 20.11.45.png (390.75 KiB) Viewed 152 times

User avatar
waaren
Posts: 1358
Joined: Tuesday 03 January 2017 15:18
Target OS: Raspberry Pi
Domoticz version: Beta
Location: Netherlands
Contact:

Re: Analog measurement

Post by waaren » Saturday 27 October 2018 20:26

Knibor wrote:
Saturday 27 October 2018 20:14
Hi,
I tried this latest code with a fresh installed Domoticz, so only this code and the new IDX
IDX 14 is the master voltage sensor, were I can read now the value 80.
IDX 13 is the slave sensor, and I read now the value "0".
IDX 15 is the voltage Switch and I with it on and off serval times. Also tried when the switch is on change the value off IDX 14 master voltage.
But no copy from IDX 14 to IDX15.

Do I something wrong?
Here is my log
As you described it, the copy should go from 14 to 13
Can you show the script how it is now and at least show the log with the debug lines of the script? Preferable in textformat within "[ code]" "[ \code]" tags
Raspberry (debian stretch via berryboot on Synology DS916+) , Domoticz (almost) latest Beta, , dzVents 2.6, RFLink, RFXtrx433e, P1, Youless, Harmony, Hue, Yeelight, Xiaomi, HomeWizard, Zwave, Amazon echo

Knibor
Posts: 50
Joined: Sunday 20 May 2018 12:56
Target OS: OS X
Domoticz version: Beta
Contact:

Re: Analog measurement

Post by Knibor » Saturday 27 October 2018 20:52

Hi, it works now

I don't now why? I only changed the file name from the script from Sample/Hold to SampleHold.
Suddenly it works!

Thank you very much for the support.

I have made a battery cell monitor. It reads the battery voltage value with Espeasy mini D1and send it (wireless) to Domoticz. The Espeasy is connected with a multiplexer and can measure 16 channels.
I send with Domotics a binary code for battery cell 1(switch) to cell 13 with an interval of 15 seconds. So when Cell 1 is measured it will go to this Sample/Hold script.....and so on until to cell 13. Now I can use 13 voltage indicators in Domoticz with the actual value.

Robin

Post Reply

Who is online

Users browsing this forum: No registered users and 4 guests