Page 1 of 1

Switch off some switches depending on power usage

Posted: Saturday 25 January 2020 11:22
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

Re: Switch off some switches depending on power usage

Posted: Saturday 25 January 2020 14:21
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.

Re: Switch off some switches depending on power usage

Posted: Saturday 25 January 2020 15:32
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]

Re: Switch off some switches depending on power usage

Posted: Saturday 25 January 2020 17:24
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' }, 





Re: Switch off some switches depending on power usage

Posted: Saturday 25 January 2020 23:14
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


Re: Switch off some switches depending on power usage

Posted: Sunday 26 January 2020 10:35
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)

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

Posted: Sunday 26 January 2020 21:14
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