Resendig iformation from a script

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

Moderator: leecollings

Post Reply
ulfh2018
Posts: 65
Joined: Sunday 11 November 2018 9:01
Target OS: Raspberry Pi / ODroid
Domoticz version: Beta
Location: Oslo
Contact:

Resendig iformation from a script

Post by ulfh2018 »

I am using the following code to send information about the wanted temperature from a setpoint to ESPeasy. This works as expected using the following code.

return {
active = true,
on = {
devices = {
'Bad'}
},
execute = function(domoticz, device)
local url= 'http://10.0.0.217/control?cmd=event,Bad='..(device.state)..''
print(url)
domoticz.openURL(url)
end}

I would like to refresh the setpoint, so it will not become red after a while but want to keep the registered temperatur until it is changed. Not sure how to do that.

Can someone please help me?

Best regards

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

Re: Resendig iformation from a script

Post by waaren »

ulfh2018 wrote: Monday 18 March 2019 21:05 I would like to refresh the setpoint, so it will not become red after a while but want to keep the registered temperatur until it is changed. Not sure how to do that.
code below does what you want but also resend the setPoint to the ESPEasy

Code: Select all

return {
            active = true, 
            
            on = { devices = { 'Bad'}},
            
    execute = function(domoticz, device)
        local url= 'http://10.0.0.217/control?cmd=event,Bad='..(device.state)..''
        print(url)
        domoticz.openURL(url)
        device.updateSetPoint(device.setPoint).afterMin(60)
    end
}
If you don't want to resend the same setPoint you will have to store the current setPoint somewhere so you can check if the setPoint has changed
Then it would be something like

Code: Select all

return {
            active = true, 
            
            on = { devices = { 'Bad'}},
            
            data = { setPoint = { initial = 0 }},
            
    execute = function(domoticz, device)
        if device.setPoint ~= domoticz.data.setPoint then
            local url= 'http://10.0.0.217/control?cmd=event,Bad='..(device.state)..''
            print(url)
            domoticz.openURL(url)
            domoticz.data.setPoint = device.setPoint
        end
        device.updateSetPoint(device.setPoint).afterMin(60)
    end
}
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
ulfh2018
Posts: 65
Joined: Sunday 11 November 2018 9:01
Target OS: Raspberry Pi / ODroid
Domoticz version: Beta
Location: Oslo
Contact:

Re: Resendig iformation from a script

Post by ulfh2018 »

Thank you so much for the answer. Very easy, if you know what to do!

What I need is to keep resendig data every X minutes until the data is changed, then I want to send the new data, and keep resending this data, not the old data.

Will this keep on repeating every 60 min or is it a one-shot, an by the way, how log is the default time before Domoticz decaler a device as "dead"?
ulfh2018
Posts: 65
Joined: Sunday 11 November 2018 9:01
Target OS: Raspberry Pi / ODroid
Domoticz version: Beta
Location: Oslo
Contact:

Re: Resendig iformation from a script

Post by ulfh2018 »

Hello again.
I tried both solutions, but they give me this error:

2019-03-19 07:19:16.695 Status: dzVents: Error (2.4.6): An error occured when calling event handler BadNede
2019-03-19 07:19:16.695 Status: dzVents: Error (2.4.6): ...i/domoticz/scripts/dzVents/generated_scripts/BadNede.lua:10: attempt to call field 'afterMin' (a nil value)
2019-03-19 07:19:16.695 Status: dzVents: Info: ------ Finished BadNede

I tried to google the error, which sent me to the following link viewtopic ... 59&t=18674, but that was about an old version of Domoticz and the solution was to use the syntax you have used. Catch 22??
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: Resendig iformation from a script

Post by waaren »

ulfh2018 wrote: Tuesday 19 March 2019 7:31 Hello again.
I tried both solutions, but they give me this error:

2019-03-19 07:19:16.695 Status: dzVents: Error (2.4.6): An error occured when calling event handler BadNede
2019-03-19 07:19:16.695 Status: dzVents: Error (2.4.6): ...i/domoticz/scripts/dzVents/generated_scripts/BadNede.lua:10: attempt to call field 'afterMin' (a nil value)
2019-03-19 07:19:16.695 Status: dzVents: Info: ------ Finished BadNede
What is the type / subtype of your device and what is your domoticz version ? (domoticz > V4.10360 needed for afterMin() method on updateSetpoint function)
If you cannot upgrade to a newer version the repeat functionality within this script need to be initiated using a workaround but my experience with recent Beta's is that they are at least as stable as the last "stable" version.
Last edited by waaren on Tuesday 19 March 2019 8:53, edited 1 time in total.
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: Resendig iformation from a script

Post by waaren »

ulfh2018 wrote: Tuesday 19 March 2019 7:08 What I need is to keep resending data every X minutes until the data is changed, then I want to send the new data, and keep resending this data, not the old data.
That is what the first script does.
Will this keep on repeating every 60 min or is it a one-shot ?
It will repeat every 60 minutes.
and by the way, how long is the default time before Domoticz declares a device as "dead"?
Default settings is 60 minutes but configurable in Web GUI via [Setup] [Settings] [Other] Sensor timeout
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
ulfh2018
Posts: 65
Joined: Sunday 11 November 2018 9:01
Target OS: Raspberry Pi / ODroid
Domoticz version: Beta
Location: Oslo
Contact:

Re: Resendig iformation from a script

Post by ulfh2018 »

Sorry for late response! Been out whole day.

I am running version 4.9700. I'll try with a beta, since this is, as far as I can see, the latest stable version. Though for some reason, now the script is sent every 10 second.
ulfh2018
Posts: 65
Joined: Sunday 11 November 2018 9:01
Target OS: Raspberry Pi / ODroid
Domoticz version: Beta
Location: Oslo
Contact:

Re: Resendig iformation from a script

Post by ulfh2018 »

Updated - seems to work, but I don't understand this code:

on = { devices = { 'Bad'}},

data = { setPoint = { initial = 0 }},

What is the purpose of setPoint, and if I need the same in another script, is this a local variable that only will be visible inside this script, or do I have to use another name if I want to use it in another script?
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: Resendig iformation from a script

Post by waaren »

ulfh2018 wrote: Tuesday 19 March 2019 18:49 Updated - seems to work, but I don't understand this code:

on = { devices = { 'Bad'}},
If device with name Bad is updated it will trigger the script
data = { setPoint = { initial = 0 }},
What is the purpose of setPoint, and if I need the same in another script, is this a local variable that only will be visible inside this script, or do I have to use another name if I want to use it in another script?
This is local persistent variable with the current value of the setpoint. It is visible to this script only.
Look at this to see how to use dzVents global persistent variables which are accessible to all dzVents scripts.
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
ulfh2018
Posts: 65
Joined: Sunday 11 November 2018 9:01
Target OS: Raspberry Pi / ODroid
Domoticz version: Beta
Location: Oslo
Contact:

Re: Resendig iformation from a script

Post by ulfh2018 »

Thank you so MUCH for all information! Things are working as expected now, but I will raise a new scenario in another topic, since I also want to try to implement without using rules on ESP Easy
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest