Set Level (variable number)

Moderator: leecollings

Post Reply
JonyBCN
Posts: 39
Joined: Tuesday 24 May 2016 22:39
Target OS: NAS (Synology & others)
Domoticz version:
Contact:

Set Level (variable number)

Post by JonyBCN »

I am starting with LUA. I am a Siemens PLC programmer, I work with a graphical interface and I do not program code, so maybe things that I take for granted are not, apologize in advance.

I am automating an awning, and I have doubts with the command (commandArray ['Device'] = 'Set Level NN').
Submitting the level works, but I'd like to give the system a twist. It is possible to do something like (commandArray ['Awning'] = 'Set Level (VARIABLE))'.
My idea is that if a strong wind gust blows, save the current level in a variable and close the awning, and when the wind gust stops, return the awning to the original position.
jannl
Posts: 625
Joined: Thursday 02 October 2014 6:36
Target OS: Raspberry Pi / ODroid
Domoticz version: 2022.2
Location: Geleen
Contact:

Re: Set Level (variable number)

Post by jannl »

Yes, that should be possible. Something with tonumber(variable) and concatenate 2 strings. I can not give an example right now, but google to lua syntax should help.

If you save it in a uservariable, it should be possible.
JonyBCN
Posts: 39
Joined: Tuesday 24 May 2016 22:39
Target OS: NAS (Synology & others)
Domoticz version:
Contact:

Re: Set Level (variable number)

Post by JonyBCN »

Well, to give you an idea of how I "program" in my work I paste this image:
Image

:lol:
So starting with LUA for me is a totally new concept and I have to get used to it.
I will try to find out more about the subject, although any help is welcome.
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: Set Level (variable number)

Post by waaren »

JonyBCN wrote: Monday 10 August 2020 20:35 I will try to find out more about the subject, although any help is welcome.
What is the device type / subtype of your awning device in domoticz as seen on the device tab and how does it look on the switch tab?

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."

if it is a selector type this could work.

Code: Select all

return
{
    on =
    {
        devices =
        {
            'myWindDevice', -- change to name of your wind sensor device
        },
    },

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

    data =
    {
        previousLevel =
        {
            initial = -1,
        },
    },

    execute = function(dz, item)
        local maxGust = 20
        local awning = dz.devices('myAwning') -- change to name of your awning

        if item.gust > maxGust and awning.levelName ~= 'Off' then
            awning.switchSelector('Off')
            dz.data.previousLevel = awning.level
        elseif item.gust < maxGust and dz.data.previousLevel ~= -1 and awning.levelName == 'Off' and awning.lastUpdate.secondsAgo > 900 then
            awning.switchSelector(dz.data.previousLevel)
            dz.data.previousLevel = -1
        end

    end
}
if it is a dimmer type you could try

Code: Select all

return
{
    on =
    {
        devices =
        {
            'myWindDevice', -- change to name of your wind sensor device
        },
    },

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

    data =
    {
        previousLevel =
        {
            initial = -1,
        },
    },

    execute = function(dz, item)
        local maxGust = 20
        local awning = dz.devices('myAwning') -- change to name of your awning

        if item.gust > maxGust and awning.state ~= 'Off' then
            awning.dimTo(0)
            dz.data.previousLevel = awning.level
        elseif item.gust < maxGust and dz.data.previousLevel ~= -1 and awning.state == 'Off' and awning.lastUpdate.secondsAgo > 900 then
            awning.dimTo(dz.data.previousLevel)
            dz.data.previousLevel = -1
        end

    end
}
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
JonyBCN
Posts: 39
Joined: Tuesday 24 May 2016 22:39
Target OS: NAS (Synology & others)
Domoticz version:
Contact:

Re: Set Level (variable number)

Post by JonyBCN »

Thank you very much for the help.

I have been doing tests (the awning is a level, Domoticz treats it as a blind) and it works, although I have had to change this: "dz.data.previousLevel = (awning.level)".

Thank you for pointing me in the correct address. Now I want to continue investigating to give it more functions.
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest