Sensor Data to virtual Sensor

Easy to use, 100% Lua-based event scripting framework.

Moderator: leecollings

Post Reply
Wolli82
Posts: 7
Joined: Monday 15 January 2018 21:28
Target OS: -
Domoticz version:
Contact:

Sensor Data to virtual Sensor

Post by Wolli82 »

Hello!

I want to copy the data from a sensor into a virtual sensor and convert the data. I have a 0-10V input that I want to convert into cash. Does anyone have an example for me?

Many Thanks
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: Sensor Data to virtual Sensor

Post by waaren »

Wolli82 wrote: Friday 17 July 2020 20:51 I want to copy the data from a sensor into a virtual sensor and convert the data. I have a 0-10V input that I want to convert into cash. Does anyone have an example for me?
What are the types / subtypes of the source and target sensors and what should be the ratio ? 10V is 10 cents or 10V is 10.000 $ or ?
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
Wolli82
Posts: 7
Joined: Monday 15 January 2018 21:28
Target OS: -
Domoticz version:
Contact:

Re: Sensor Data to virtual Sensor

Post by Wolli82 »

There was a spelling mistake. This is the Sensor with 0-10V
Anmerkung 2020-07-17 220645.png
Anmerkung 2020-07-17 220645.png (12.51 KiB) Viewed 1917 times
And i will fill this virtual Sensor
Anmerkung 2020-07-17 220646.png
Anmerkung 2020-07-17 220646.png (13.89 KiB) Viewed 1917 times
0V is 0 bar and 10V is 10 bar.

For a flow meter i must do the same, but i don´t know the ratio now.
So i would like an example to change the conversion myself.

Thank you in advance for the help!
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: Sensor Data to virtual Sensor

Post by waaren »

Wolli82 wrote: Friday 17 July 2020 22:11 So i would like an example to change the conversion myself.
Could look like below in dzVents

When not yet familiar with dzVents please start with reading Get started Before implementing (~ 5 minutes). Special attention please for "In Domoticz go to Setup > Settings > Other and in the section EventSystem make sure the checkbox 'dzVents enabled' is checked. Also make sure that in the Security section in the settings you allow 127.0.0.1 to not need a password. dzVents uses that port to send certain commands to Domoticz. Finally make sure you have set your current location in Setup > Settings > System > Location, otherwise there is no way to determine nighttime/daytime state."

Code: Select all

return
{
    on =
    {
        devices =
        {
            'Brunnenpumpe Druck',
        },
    },

    logging =
    {
        level = domoticz.LOG_DEBUG, -- change to domiticz.LOG_ERROR when all OK
        marker = 'Conversion',
    },

    execute = function(dz, item)
        dz.devices('Brunnenpumpe Druck1').updatePressure(item.voltage)
    end
}
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
Wolli82
Posts: 7
Joined: Monday 15 January 2018 21:28
Target OS: -
Domoticz version:
Contact:

Re: Sensor Data to virtual Sensor

Post by Wolli82 »

I have tested the script but unfortunately nothing works. Do you have another idea?
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: Sensor Data to virtual Sensor

Post by waaren »

Wolli82 wrote: Saturday 18 July 2020 18:38 I have tested the script but unfortunately nothing works. Do you have another idea?
I also tested the script (before posting) and it works as expected. When I update the voltage sensor the pressure sensor gets updated
Volt2Bar.png
Volt2Bar.png (20.06 KiB) Viewed 1864 times
Please provide more detail about the circumstances and relevant loglines. This will make searching why it does not work for you, easier for other forum members.

So how do you update the voltage meter. And can you show the loglines of this update
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
Wolli82
Posts: 7
Joined: Monday 15 January 2018 21:28
Target OS: -
Domoticz version:
Contact:

Re: Sensor Data to virtual Sensor

Post by Wolli82 »

It works now, thank you very much!!!
Can you help me to another problem?
I have a Switch "Brunnenpumpe Ein/Aus".
If "Brunnenpumpe Ein/Aus" is on and the value for "Brunnenpumpe Druck" >= 3V then the dimmer-switch "Brunnenpumpe Drehzahl" should be switched off.
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: Sensor Data to virtual Sensor

Post by waaren »

Wolli82 wrote: Tuesday 21 July 2020 16:36 I have a Switch "Brunnenpumpe Ein/Aus".
If "Brunnenpumpe Ein/Aus" is on and the value for "Brunnenpumpe Druck" >= 3V then the dimmer-switch "Brunnenpumpe Drehzahl" should be switched off.
Below script combines the two requirements (Conversion and Control)

Code: Select all

local voltMeterName = 'Brunnenpumpe Druck'
local pumpSwitchName = 'Brunnenpumpe Ein/Aus' 

return
{
    on =
    {
        devices =
        {
            voltMeterName,
            pumpSwitchName,
        },
    },

    logging =
    {
        level = domoticz.LOG_DEBUG, -- change to domoticz.LOG_ERROR when all OK
        marker = 'Conversion and Control',
    },

    execute = function(dz, item)
        local pressureSensor = dz.devices('Brunnenpumpe Druck1') 
        local rotationalSpeed = dz.devices('Brunnenpumpe Drehzahl') 
        local voltMeter = dz.devices(voltMeterName)
        local pumpSwitch = dz.devices(pumpSwitchName)
        
        if item == voltMeter then
            pressureSensor.updatePressure(item.voltage)
        end
        
        if ( voltMeter.voltage >= 3 ) and  pumpSwitch.active and rotationalSpeed.state ~= 'Off' then
            rotationalSpeed.dimTo(0)
        end
        
    end
}
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
Wolli82
Posts: 7
Joined: Monday 15 January 2018 21:28
Target OS: -
Domoticz version:
Contact:

Re: Sensor Data to virtual Sensor

Post by Wolli82 »

Thanks, it works perfect!!
Here is my script, but i would like to convert the water flow sensor value with a factor of 0.01. Do you have another idea?

Code: Select all

local voltMeterName = 'Brunnenpumpe Druck'
local voltMeter1Name = 'Brunnenpumpe Durchfluss'
local pumpSwitchName = 'Brunnenpumpe Ein/Aus'


return
{
    on =
    {
        devices =
        {
            voltMeterName,
            voltMeter1Name,
            pumpSwitchName,
        },
    },

    logging =
    {
        level = domoticz.LOG_DEBUG, -- change to domoticz.LOG_ERROR when all OK
        marker = 'Conversion and Control',
        marker = 'Conversion and Control1',
    },

    execute = function(dz, item)
        local pressureSensor = dz.devices('Brunnenpumpe Drucksensor') 
        local waterflowSensor = dz.devices('Brunnenpumpe Durchflusssensor') 
        local rotationalSpeed = dz.devices('Brunnenpumpe Drehzahl') 
        local voltMeter = dz.devices(voltMeterName)
        local voltMeter1 = dz.devices(voltMeter1Name)
        local pumpSwitch = dz.devices(pumpSwitchName)
        
    --Volt in Bar    
        
        if item == voltMeter then
            pressureSensor.updatePressure(item.voltage)
        end
        
    --Volt in Liter pro Minute
    
        if item == voltMeter1 then
            waterflowSensor.updateWaterflow(item.voltage)
        end
    
    --Abschaltung Pumpe über 3 Bar
        
        if ( voltMeter.voltage >= 3 ) and  pumpSwitch.active then 
            rotationalSpeed.switchOff()
            dz.log('Druck ueber 3 bar')
        end
        
    --Einschaltung unter 1 Bar    
        
        if ( voltMeter.voltage <= 1 ) and  pumpSwitch.active then 
            rotationalSpeed.switchOn()
            dz.log('Druck unter 1 bar')
        end    
    end
}
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: Sensor Data to virtual Sensor

Post by waaren »

Wolli82 wrote: Wednesday 22 July 2020 14:28 Thanks, it works perfect!!
Here is my script, but i would like to convert the water flow sensor value with a factor of 0.01. Do you have another idea?
Not sure I understand what you write but would this do ?
change line 42 from

Code: Select all

 waterflowSensor.updateWaterflow(item.voltage) 
to

Code: Select all

 waterflowSensor.updateWaterflow(item.voltage * 0.01 )
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
ssk17051980
Posts: 112
Joined: Thursday 08 December 2022 22:15
Target OS: Raspberry Pi / ODroid
Domoticz version: 2023.2
Location: ROMANIA
Contact:

Re: Sensor Data to virtual Sensor

Post by ssk17051980 »

what presure sensor do you use ?
Post Reply

Who is online

Users browsing this forum: Google [Bot] and 1 guest