Switch off some switches depending on power usage  [Solved]

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

Moderator: leecollings

Post Reply
salvacalatayud
Posts: 112
Joined: Monday 26 June 2017 21:16
Target OS: Raspberry Pi / ODroid
Domoticz version: beta
Location: Spain
Contact:

Switch off some switches depending on power usage

Post by salvacalatayud »

Hello friends, first of all sorry but I'm not programer and I have no idea of what I'm doing wrong.

I'm having problems with my energy usage, if too many things are On the electric company switches off the entire home. So I want to switch off some switches depending on power usage.

I've tried with this code but nothing happens:

Code: Select all


return {
    on = {
    	timer = { 'every minute' }
        devices = {
            'contador',
            'calefaccion_Bernat',
            'calefaccion_papis',
            'calentador'
        }
    },
    execute = function(domoticz, device)
        local contador = domoticz.devices(92)
        local calefaccion_Bernat = domoticz.devices(11)
        local calefaccion_papis = domoticz.devices(137)
        local calentador = domoticz.devices(6)

        if (contador.actualWatt > 3250 and calefaccion_Bernat.state == 'On') then
                calefaccion_Bernat.switchOff().forMin(10)
                domoticz.notify ('Consumo alto, apago calefaccion','Consumo alto, apago calefaccion')
        end
    if (contador.actualWatt > 3350 and calefaccion_papis.state == 'On') then
                calefaccion_papis.switchOff().forMin(9)
                domoticz.notify ('Consumo alto, apago calefaccion','Consumo alto, apago calefaccion')
        end
    if (contador.actualWatt > 3450 and calentador.state == 'On') then
                calentador.switchOff().forMin(11)
                domoticz.notify ('Consumo alto, apago calentador','Consumo alto, apago calentador')
        end
end

}

If someone can tell me what is wrong I would appreciate

Thanks
Last edited by salvacalatayud on Saturday 25 January 2020 16:03, edited 1 time in total.
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: Switch off some switches depending on power usage

Post by waaren »

salvacalatayud wrote: Saturday 25 January 2020 11:22 I'm having problems with my energy usage, if too many things are On the electric company switches off the entire home. So I want to switch off some switches depending on power usage.
I've tried with this code but nothing happens:
Please state your OS, your domoticz-version (is it really 3.8072 mentioned in your profile ?) and dzVents version and show us what you see in the log first. Without that information it's very hard to find any issues.
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
salvacalatayud
Posts: 112
Joined: Monday 26 June 2017 21:16
Target OS: Raspberry Pi / ODroid
Domoticz version: beta
Location: Spain
Contact:

Re: Switch off some switches depending on power usage

Post by salvacalatayud »

waaren wrote: Saturday 25 January 2020 14:21
salvacalatayud wrote: Saturday 25 January 2020 11:22 I'm having problems with my energy usage, if too many things are On the electric company switches off the entire home. So I want to switch off some switches depending on power usage.
I've tried with this code but nothing happens:
Please state your OS, your domoticz-version (is it really 3.8072 mentioned in your profile ?) and dzVents version and show us what you see in the log first. Without that information it's very hard to find any issues.
Sorry, I thought it was a coding matter.

I'm running latest beta
OS raspbian stretch (updated)
dzVents Version: 2.5.7

Log errors found:

Code: Select all

2020-01-25 15:58:54.829 Error: dzVents: Error: (2.5.7) error loading module 'apaga_todos_potencia' from file '/home/pi/domoticz/scripts/dzVents/generated_scripts/apaga_todos_potencia.lua':
2020-01-25 15:58:54.829 ...ripts/dzVents/generated_scripts/apaga_todos_potencia.lua:4: '}' expected (to close '{' at line 2) near 'devices'
[\code]
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: Switch off some switches depending on power usage

Post by waaren »

It is but with the log it is so much easyer to find.

You missed a comma behind

Code: Select all

timer = { 'every minute' }
It must be

Code: Select all

timer = { 'every minute' }, 




Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
salvacalatayud
Posts: 112
Joined: Monday 26 June 2017 21:16
Target OS: Raspberry Pi / ODroid
Domoticz version: beta
Location: Spain
Contact:

Re: Switch off some switches depending on power usage

Post by salvacalatayud »

waaren wrote:It is but with the log it is so much easyer to find.

You missed a comma behind

Code: Select all

timer = { 'every minute' }
It must be

Code: Select all

timer = { 'every minute' }, 
Thanks, it looks like working now, no log errors. But the .forMin() doesn't work, it switches off but never switch on after the desired time.

Enviado desde mi Mi A2 mediante Tapatalk

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

Re: Switch off some switches depending on power usage

Post by waaren »

salvacalatayud wrote: Saturday 25 January 2020 23:14 The .forMin() doesn't work, it switches off but never switch on after the desired time.
I am not a big fan of the forXXX() approach myself. What I normally do is something like

Code: Select all

                calefaccion_Bernat.cancelQueuedCommands()
                calefaccion_Bernat.switchOff()
                calefaccion_Bernat.switchOn().afterMin(10)
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
salvacalatayud
Posts: 112
Joined: Monday 26 June 2017 21:16
Target OS: Raspberry Pi / ODroid
Domoticz version: beta
Location: Spain
Contact:

Re: Switch off some switches depending on power usage  [Solved]

Post by salvacalatayud »

waaren wrote:
salvacalatayud wrote: Saturday 25 January 2020 23:14 The .forMin() doesn't work, it switches off but never switch on after the desired time.
I am not a big fan of the forXXX() approach myself. What I normally do is something like

Code: Select all

                calefaccion_Bernat.cancelQueuedCommands()
                calefaccion_Bernat.switchOff()
                calefaccion_Bernat.switchOn().afterMin(10)
Done, now is working perfect

Enviado desde mi Mi A2 mediante Tapatalk

Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest