Change a Switch with a text device

Moderator: leecollings

Post Reply
Svennie
Posts: 13
Joined: Sunday 25 October 2020 14:57
Target OS: Raspberry Pi / ODroid
Domoticz version: 2022.1
Location: Helmond
Contact:

Change a Switch with a text device

Post by Svennie »

Hello,

I have a text device that gives my the status of my Roomba robot. The status can be "Running", "Stopped" and "End Mission".
I would like to activate a switch based on a status change with blocky.
Schermafbeelding 2021-01-26 om 21.48.22.png
Schermafbeelding 2021-01-26 om 21.48.22.png (56.91 KiB) Viewed 1158 times
I would like to achieved the following:

If RoombaS9 State = Running
do set Dummy test = on

I use a Dummy switch now. When I got the script working I will switch the dummy for a group of lights/ switches.
Schermafbeelding 2021-01-26 om 21.51.38.png
Schermafbeelding 2021-01-26 om 21.51.38.png (43.79 KiB) Viewed 1158 times
This is what I created in Blocky now. But that isn't working.

I hope someone can help me.

Thank you for your help in advance.

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

Re: Change a Switch with a text device

Post by waaren »

Svennie wrote: Tuesday 26 January 2021 21:55 ... But that isn't working.
According to the tooltip (see below) the block is for assigning a value to a text sensor. You cannot use this block to read the value of a text device. I don't think you can do this in Blockly.
text device.png
text device.png (9.76 KiB) Viewed 1151 times
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
Svennie
Posts: 13
Joined: Sunday 25 October 2020 14:57
Target OS: Raspberry Pi / ODroid
Domoticz version: 2022.1
Location: Helmond
Contact:

Re: Change a Switch with a text device

Post by Svennie »

Waaren,

I see we are both Dutchmen. Can we continu in Dutch?

For now I will do it in English.

Is there a way to do what I want in a different way? Beside Blocky?

Thnx
User avatar
waltervl
Posts: 5904
Joined: Monday 28 January 2019 18:48
Target OS: Linux
Domoticz version: 2024.7
Location: NL
Contact:

Re: Change a Switch with a text device

Post by waltervl »

You can ask the plugin writer to make it a selector switch instead of a text widget. Then you can set actions on the state change of switch.

Or you can use DzVents scripting to read the status and switch the dummy (or later your lighting group). A lot of examples in the excellent documentation on the wiki https://www.domoticz.com/wiki/DzVents:_ ... _scripting
Domoticz running on Udoo X86 (on Ubuntu)
Devices/plugins: ZigbeeforDomoticz (with Xiaomi, Ikea, Tuya devices), Nefit Easy, Midea Airco, Omnik Solar, Goodwe Solar
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: Change a Switch with a text device

Post by waaren »

Svennie wrote: Wednesday 27 January 2021 18:24 I see we are both Dutchmen. Can we continu in Dutch?
@Svennie, the forum is international so please continue in English. @walterv already answered the question.
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
Svennie
Posts: 13
Joined: Sunday 25 October 2020 14:57
Target OS: Raspberry Pi / ODroid
Domoticz version: 2022.1
Location: Helmond
Contact:

Re: Change a Switch with a text device

Post by Svennie »

waltervl wrote: Wednesday 27 January 2021 18:56 You can ask the plugin writer to make it a selector switch instead of a text widget. Then you can set actions on the state change of switch.

Or you can use DzVents scripting to read the status and switch the dummy (or later your lighting group). A lot of examples in the excellent documentation on the wiki https://www.domoticz.com/wiki/DzVents:_ ... _scripting
Hello Waltvl,

Thank you for your response. Can you give me an example of Dzvents script? That I can use in my case? I'm a Noob in Dzvents. I did read the wiki you mentioned but I couldn't find my answer.
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: Change a Switch with a text device

Post by waaren »

Svennie wrote: Wednesday 27 January 2021 20:35 Can you give me an example of Dzvents script? That I can use in my case? I'm a Noob in Dzvents. I did read the wiki you mentioned but I couldn't find my answer.
Your Blockly converted to a working dzVents script.

Code: Select all

return
{
    on =
    {
        devices =
        {
            'RoombaS9-State', -- Name of your device
        },
    },

    logging =
    {
        level = domoticz.LOG_DEBUG,
        marker = 'Roomba',
    },

    execute = function(dz, item)
        if item.text == 'Running' then
            dz.devices('Dummy test').switchOn()
        end
    end
}
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
Svennie
Posts: 13
Joined: Sunday 25 October 2020 14:57
Target OS: Raspberry Pi / ODroid
Domoticz version: 2022.1
Location: Helmond
Contact:

Re: Change a Switch with a text device

Post by Svennie »

waaren wrote: Wednesday 27 January 2021 22:31 Your Blockly converted to a working dzVents script.
Waaren,

Thank you for your script. Unfortunately it's not working. I took a look at it. But I didn't find the error or found the solution. Do you have any clue?

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

Re: Change a Switch with a text device

Post by waaren »

Svennie wrote: Friday 29 January 2021 21:42 Thank you for your script. Unfortunately it's not working. I took a look at it. But I didn't find the error or found the solution. Do you have any clue?
"it's not working" is usually not enough to start looking for a root cause :D
  • did you read the getting started with 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."
    ___________________________________________________________________________________________________________________________
  • Did you double check the device names used in the script? They need to be exactly equal to the names on your system
  • What do you see in the domoticz log when saving this script as a dzVents event-script
  • What do you see in the log when the text in your status device is set to 'Running'
I added some extra debug lines in below version to force some log lines no matter what the text changes to.

Code: Select all


return
{
    on =
    {
        devices =
        {
            'RoombaS9-State', -- Name of your device
        },
    },

    logging =
    {
        level = domoticz.LOG_DEBUG,
        marker = 'Roomba',
    },

    execute = function(dz, item)

        dz.log(item.name .. 'is now "' .. item.text .. '"', dz.LOG_DEBUG)

        if item.text == 'Running' then
            dz.devices('Dummy test').switchOn()
        end
    end
}
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest