Text device to virtual device

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

Moderator: leecollings

Post Reply
edwin1234
Posts: 330
Joined: Sunday 09 October 2016 20:20
Target OS: Raspberry Pi / ODroid
Domoticz version: 2021.1
Location: Nederland
Contact:

Text device to virtual device

Post by edwin1234 »

Is it in dzvents possible to set a virtual device to :
“Hot water on”
If my text device is “=H”
And that virtual device to:
“Hot water off”
If my text device is something else like:
“-H” , “0H” , “0Y”
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: Text device to virtual device

Post by waaren »

edwin1234 wrote: Sunday 01 March 2020 7:51 Is it in dzvents possible to set a virtual device to :
“Hot water on”
If my text device is “=H”
And that virtual device to:
“Hot water off”
If my text device is something else like:
“-H” , “0H” , “0Y”
Just to make sure I understand the question. You want to change the text in textdevice based on a string entered in the same textdevice ?
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
edwin1234
Posts: 330
Joined: Sunday 09 October 2016 20:20
Target OS: Raspberry Pi / ODroid
Domoticz version: 2021.1
Location: Nederland
Contact:

Re: Text device to virtual device

Post by edwin1234 »

No i want another virtual device changed to hot water on or off based on the text device that gives =H for water on and if it gives another output for hot water off, hot water off must be if the text device gives 0y or 0a or -H
Hope you understand , my english is not so good 😉

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

Re: Text device to virtual device

Post by waaren »

edwin1234 wrote: Monday 02 March 2020 7:01 No i want another virtual device changed to hot water on or off based on the text device that gives =H for water on and if it gives another output for hot water off, hot water off must be if the text device gives 0y or 0a or -H
OK.
Is 'another virtual device' also a text device ?
If not please post name, type and subtype.
The example below assumes a text device.

Code: Select all

return
{
    on =
    {
        devices =
        {
            'sourceText', -- change to name of source device
        },
    },

    logging =
    {
        level = domoticz.LOG_DEBUG,                        -- INFO, DEBUG or ERROR
        marker = 'Text2Text'
    },

    execute = function(dz, item)
        local targetDevice = dz.devices('targetText') -- change to name of target device

        local sourceText = item.text
        local targetText = 'Hot water off'

        if sourceText:match('=H') then -- if source device contains string '=H'
            targetText = 'Hot water on'
        end

        dz.log('\nsourceText: ' .. item.text .. '\ntargetText: ' .. targetText ,dz.LOG_DEBUG)

        if targetDevice.text ~= targetText then -- only change target when not equal to targettext
            targetDevice.updateText(targetText)
        end
    end
}
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
edwin1234
Posts: 330
Joined: Sunday 09 October 2016 20:20
Target OS: Raspberry Pi / ODroid
Domoticz version: 2021.1
Location: Nederland
Contact:

Re: Text device to virtual device

Post by edwin1234 »

Thank u very much for your help
I’ m gonna try this out.

Regards
Edwin
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest