Little script help please?  [Solved]

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

Moderator: leecollings

Post Reply
theolsen
Posts: 46
Joined: Wednesday 31 July 2013 11:15
Target OS: -
Domoticz version:
Contact:

Little script help please?

Post by theolsen »

Hi all,

I am a complete noob to dzVents and am not a coder by any stretch of the imagination.

I am looking for a way of scripting the following:

Check a dummy device once every minute and if the text does not equal "whatever" then turn off a smart plug.


Any help would be very much appreciated.

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

Re: Little script help please?

Post by waaren »

theolsen wrote: Tuesday 01 December 2020 17:18 I am looking for a way of scripting the following: Check a dummy device once every minute and if the text does not equal "whatever" then turn off a smart plug.
could look like below example
__________________________________________________________________________________________________________________________
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 =
    {
        timer =
        {
            'every minute',
        },
    },

    logging =
    {
        level = domoticz.LOG_DEBUG, -- set to domoticz.LOG_ERROR when all OK to surpress log entries
        marker = 'Whatever',
    },

    execute = function(dz)
        local text = dz.devices('name of your text device').text -- Change between quotes (must be text device)
        local smartPlug = dz.devices('name of you Smartplug') -- Change between quotes (must be a switch type device)

        if text ~= 'whatever' then
            smartPlug.switchOff()
        end
    end
}
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
theolsen
Posts: 46
Joined: Wednesday 31 July 2013 11:15
Target OS: -
Domoticz version:
Contact:

Re: Little script help please?  [Solved]

Post by theolsen »

Hey, thanks a million @waaren. And thanks for the link to Get Started.

Much appreciated.
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest