Script or Blockly for activate switch when battery is low

Post Reply
NetEye
Posts: 34
Joined: Friday 17 June 2016 7:57
Target OS: Raspberry Pi
Domoticz version: Beta
Location: Spijkenisse
Contact:

Script or Blockly for activate switch when battery is low

Post by NetEye » Tuesday 14 August 2018 15:31

I have a 24V battery which I monitor with a INA219 (Volt), I manually start the charger with a relais by a switch in domoticz.
Can anyone help me to make this action automatic?
For instance when the INA219 shows 23 Volt, -> activate the switch which starts the charger.
I use ESPEasy and a RPi as controller.
The voltage reading is a INA219 sensor connected to a ESP8266 with ESPEasy as software which measures voltage.
What I liked to have is for instance at 23 Volt it can activate an relais which is connected also to the ESP.
The relay works with the command:
Http://<ESP IP adresss>/control?cmd=GPIO,<pin>,0
Http://<ESP IP adresss>/control?cmd=GPIO,<pin>,1
(One for start and one for stop).
I read about rules in ESPEasy or Blockly in Domoticz and also there is a way with scripts.
I’am not familiar with these, maybe someone who can coach me?
Maybe somebody has a script which I maybe can modify to my wishes?
Regards
Last edited by NetEye on Sunday 19 August 2018 9:29, edited 1 time in total.

User avatar
waaren
Posts: 1216
Joined: Tuesday 03 January 2017 15:18
Target OS: Raspberry Pi
Domoticz version: Beta
Location: Netherlands
Contact:

Re: Script or Blockly for activate switch when battery is low

Post by waaren » Tuesday 14 August 2018 19:20

NetEye wrote:
Tuesday 14 August 2018 15:31
I have a 24V battery which I monitor with a INA219 (Volt), I manually start the charger with a relais by a switch in domoticz.
Can anyone help me to make this action automatic?
For instance when the INA219 shows 23 Volt, -> activate the switch which starts the charger.
I use ESPEasy and a RPi as controller.
Maybe somebody has a script which I maybe can modify to my wishes?
Regards
How do you readout the batterylevel now ? Do you have a URL or domoticz sensor for that ?
Raspberry (debian stretch via berryboot on Synology DS916+) , Domoticz (almost) latest Beta, , dzVents 2.6, RFLink, RFXtrx433e, P1, Youless, Harmony, Hue, Yeelight, Xiaomi, HomeWizard, Zwave, Amazon echo

NetEye
Posts: 34
Joined: Friday 17 June 2016 7:57
Target OS: Raspberry Pi
Domoticz version: Beta
Location: Spijkenisse
Contact:

Re: Script or Blockly for activate switch when battery is low

Post by NetEye » Sunday 19 August 2018 9:16

Hallo waaren, thanks for your quick answer.
The voltage reading is a INA219 sensor connected to a ESP8266 with ESPEasy as software which measures voltage.
What I liked to have is for instance at 23 Volt it can activate an relais which is connected also to the ESP.
The relay works with the command:
Http://<ESP IP adresss>/control?cmd=GPIO,<pin>,0
Http://<ESP IP adresss>/control?cmd=GPIO,<pin>,1
(One for start and one for stop).
I read about rules in ESPEasy or Blockly in Domoticz and also there is a way with scripts.
I’am not familiar with these, maybe someone (you?) can coach me?
Hope I informed you complete?
Regards,
Jan

User avatar
waaren
Posts: 1216
Joined: Tuesday 03 January 2017 15:18
Target OS: Raspberry Pi
Domoticz version: Beta
Location: Netherlands
Contact:

Re: Script or Blockly for activate switch when battery is low

Post by waaren » Monday 20 August 2018 0:50

NetEye wrote:
Sunday 19 August 2018 9:16
The voltage reading is a INA219 sensor connected to a ESP8266 with ESPEasy as software which measures voltage.
The relay works with the command:
Http://<ESP IP adresss>/control?cmd=GPIO,<pin>,0
Http://<ESP IP adresss>/control?cmd=GPIO,<pin>,1
(One for start and one for stop).
Some additional questions: do you see the voltage in domoticz and if so what is the name of that virtual voltage meter ?
Raspberry (debian stretch via berryboot on Synology DS916+) , Domoticz (almost) latest Beta, , dzVents 2.6, RFLink, RFXtrx433e, P1, Youless, Harmony, Hue, Yeelight, Xiaomi, HomeWizard, Zwave, Amazon echo

NetEye
Posts: 34
Joined: Friday 17 June 2016 7:57
Target OS: Raspberry Pi
Domoticz version: Beta
Location: Spijkenisse
Contact:

Re: Script or Blockly for activate switch when battery is low

Post by NetEye » Monday 20 August 2018 8:11

Dear waaren,
Yes I can see the voltage in domoticz on it’s own id nr and his name is: Licht accu
Regards
Jan

User avatar
waaren
Posts: 1216
Joined: Tuesday 03 January 2017 15:18
Target OS: Raspberry Pi
Domoticz version: Beta
Location: Netherlands
Contact:

Re: Script or Blockly for activate switch when battery is low

Post by waaren » Monday 20 August 2018 12:15

NetEye wrote:
Monday 20 August 2018 8:11
Dear waaren,
Yes I can see the voltage in domoticz on it’s own id nr and his name is: Licht accu
Regards
Jan
I hope I understand your requirements and setup correctly.
If not; please do not hesitate...

Look at the 10 lines Using dzVents with Domoticz for a short intro to dzVents and howto get this script active in domoticz.

Code: Select all

-- operateRelay.lua
 
return { 
    on      =   {   timer          =    { "every 10 minutes" }}, 
                    
    logging =   {   level       =   domoticz.LOG_DEBUG,                                   
                    marker      =  "operateRelay" },
                    
    execute = function(dz)
        -- Modify values below this line ----------
        relaySwitch     = dz.devices("relaySwitch") -- Name of your relaySwitch within quotes or idx without quotes
        voltageSensor   = dz.devices("Licht accu")  -- Name of your voltageSensor within quotes or idx without quotes
        lowVoltage      = 23                        -- below this value the switch will be turned on
        highVoltage     = 23.5                      -- Above this value the switch will be turned off 
        hysteresisDelay = 10                        -- Delay to prevent too frequent on/off actions
        -- Modify values above this line ----------
        
        if relaySwitch.lastUpdate.minutesAgo > hysteresisDelay then
            if voltageSensor.voltage > highVoltage then
                relaySwitch.switchOff().checkFirst()
            elseif voltageSensor.voltage < lowVoltage then
                relaySwitch.switchOff().checkFirst()
            end    
        end
    end
}
Raspberry (debian stretch via berryboot on Synology DS916+) , Domoticz (almost) latest Beta, , dzVents 2.6, RFLink, RFXtrx433e, P1, Youless, Harmony, Hue, Yeelight, Xiaomi, HomeWizard, Zwave, Amazon echo

Post Reply

Who is online

Users browsing this forum: genepi and 3 guests