Rule/script or blockly

Moderators: grovkillen, Stuntteam, TD-er

Post Reply
Message
Author
NetEye
Normal user
Posts: 51
Joined: 22 Jun 2016, 00:48

Rule/script or blockly

#1 Post by NetEye » 19 Aug 2018, 10:38

Hallo,
I have a 24V battery which I monitor with a INA219 (Volt), I now 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

TD-er
Core team member
Posts: 8643
Joined: 01 Sep 2017, 22:13
Location: the Netherlands
Contact:

Re: Rule/script or blockly

#2 Post by TD-er » 19 Aug 2018, 19:56

If the INA219 and the relais are on the same ESP node, I would use rules to act on these changes.
See: https://www.letscontrolit.com/wiki/inde ... rial_Rules

You also have to keep in mind that connecting the charger will probably increase the voltage on the battery. So you have to take that into account, or else the relais will switch continuously.

NetEye
Normal user
Posts: 51
Joined: 22 Jun 2016, 00:48

Re: Rule/script or blockly

#3 Post by NetEye » 20 Aug 2018, 08:21

Dear TD-er,
Both are not on the same ESP and I read the userguide on letscontrit.
But writing a rule is not my thing.
In that case I was wondering if someone has a rule or script which I can change to my wishes.
Regards

User avatar
toffel969
Normal user
Posts: 469
Joined: 03 Jan 2017, 10:58
Location: Germany

Re: Rule/script or blockly

#4 Post by toffel969 » 20 Aug 2018, 10:55

Hi Neteye

The desired functionality can be achieved using rules, sending http commands from one unit to the other.

Please provide us with:

- Screenshots of the devices pages of both esp

- Ip adresses of both esp

I am sure we can figure it out.
Domoticz on Raspi 2 -- 14 ESP units (hacked Sonoff,NodeMCUs, Wemos, self-built units) running with RC140- Mega 2.0.0 dev8

NetEye
Normal user
Posts: 51
Joined: 22 Jun 2016, 00:48

Re: Rule/script or blockly

#5 Post by NetEye » 20 Aug 2018, 16:07

I’am not around.
I will collect it soon

NetEye
Normal user
Posts: 51
Joined: 22 Jun 2016, 00:48

Re: Rule/script or blockly

#6 Post by NetEye » 24 Aug 2018, 07:30

Dear TD-er and toffel969,
Great that you have some time for me, trying to solve it.
After research the INA219 and the relay are on the same ESP.
I have 3x 24V batteries, accu 1,accu 2 and accu 3 (see attachment 8,9 and 10)
And the relay is working via a IO Expander PCF8574 (see attachment 7).
Every batterie will be able to activate the relay, resulting in starting the 24V charger which feeds 3 diodes to the to be loaded batterie.
I hope this is the information you wanted.
Hope it will be a succes.
Regards
Attachments
relay.png
relay.png (142.6 KiB) Viewed 16306 times
8 Voltage & current (DC) INA219.PNG
8 Voltage & current (DC) INA219.PNG (149.22 KiB) Viewed 16306 times
9 Voltage & current (DC) INA219.PNG
9 Voltage & current (DC) INA219.PNG (149.24 KiB) Viewed 16306 times
10 Voltage & current (DC) INA219.PNG
10 Voltage & current (DC) INA219.PNG (149.68 KiB) Viewed 16306 times

User avatar
toffel969
Normal user
Posts: 469
Joined: 03 Jan 2017, 10:58
Location: Germany

Re: Rule/script or blockly

#7 Post by toffel969 » 24 Aug 2018, 09:37

NetEye wrote: 24 Aug 2018, 07:30 Dear TD-er and toffel969,
Great that you have some time for me, trying to solve it.
After research the INA219 and the relay are on the same ESP.
I have 3x 24V batteries, accu 1,accu 2 and accu 3 (see attachment 8,9 and 10)
And the relay is working via a IO Expander PCF8574 (see attachment 7).
Every batterie will be able to activate the relay, resulting in starting the 24V charger which feeds 3 diodes to the to be loaded batterie.
I hope this is the information you wanted.
Hope it will be a succes.
Regards
Hi neteye

Let's try to get you started. Be aware I cannot test any code at the moment and therefore there might be bugs.

You have to activate rules under the advanced tab. After doing that a new tab called "Rules" will appear on the web interface.

In the rules you type:

Code: Select all

On Accu 1#Voltage<23 do 	// when the voltage drops below 23V on Accu 1
pcfgpio,7,0 		// activate the relay, it might be 0/1 depending if your relay is active high or low, this is for active low
Timerset,1,600		// set a timer to 10 minutes (600sec), we cannot depend on voltage, see TD-er comment, adjust 
Endon

On Accu 2#Voltage<23 do 	// when the voltage drops below 23V on Accu 2
pcfgpio,7,0 		// activate the relay, it might be 0/1 depending if your relay is active high or low, this is for active low
Timerset,1,600		// set a timer to 10 minutes (600sec), we cannot depend on voltage, see TD-er comment, adjust 
Endon

On gell Accu 3#Voltage<23 do 	// when the voltage drops below 23V on Accu 3
pcfgpio,7,0 		// activate the relay, it might be 0/1 depending if your relay is active high or low, this is for active low
Timerset,1,600		// set a timer to 10 minutes (600sec), we cannot depend on voltage, see TD-er comment, adjust 
Endon

On Rules#timer=1 do  	//after 10 minutes switch the relay off. If the voltage then drops below the 23V again, the charge cycle will be triggered again.
pcfgpio,7,1			//switch off the relay 
Endon 

Try out and give us feedback
Domoticz on Raspi 2 -- 14 ESP units (hacked Sonoff,NodeMCUs, Wemos, self-built units) running with RC140- Mega 2.0.0 dev8

NetEye
Normal user
Posts: 51
Joined: 22 Jun 2016, 00:48

Re: Rule/script or blockly

#8 Post by NetEye » 25 Aug 2018, 20:44

Dear toffel969,
Thank you very much for your time, super!!
Today I implemented your rule but unfortunately it did not work (in the 2 attachments "implemented rule and switch value" you can see that the switch value remains "0".
For the test I made some short-live changes (24.8V instead of 23).
For what I noticed: you mentioned pcfgpio,7 in your rule but in my case I think it has to be pcfgpio,4 with "0" for out and 1 for on action ( because Domoticz uses pcfgpio,4 therefore I think it has to be pcfgpio,4).
For what I wish is: yours mentioned 23V as actioner for the relay to start the charger for at least 24 hours instead of 10 minutes 86400 seconds instead of 600 sec ??
This makes the thing user TD-er said (a good observation) about continuously restarting no issue.
I reviewed the rule (see attachment: reviewed rule)
Only for the yellow highlighted (On Rules#timer=1) I like it to stop after 24hours (it will not drop then under 23 after 24hrs of loading)
Am I right?
Maybe if you have some time for me, you can look at the reviewed rule then I will test its again.
Regards
Attachments
switch value.PNG
switch value.PNG (250.75 KiB) Viewed 16256 times
implemented rule.PNG
implemented rule.PNG (245.76 KiB) Viewed 16256 times
reviewed rule.png
reviewed rule.png (170.17 KiB) Viewed 16256 times
Last edited by NetEye on 25 Aug 2018, 21:16, edited 2 times in total.

User avatar
grovkillen
Core team member
Posts: 3621
Joined: 19 Jan 2017, 12:56
Location: Hudiksvall, Sweden
Contact:

Re: Rule/script or blockly

#9 Post by grovkillen » 25 Aug 2018, 21:15

I advice you to not use spaces in names. And please use the web log viewer to see what is happening.
ESP Easy Flasher [flash tool and wifi setup at flash time]
ESP Easy Webdumper [easy screendumping of your units]
ESP Easy Netscan [find units]
Official shop: https://firstbyte.shop/
Sponsor ESP Easy, we need you :idea: :idea: :idea:

NetEye
Normal user
Posts: 51
Joined: 22 Jun 2016, 00:48

Re: Rule/script or blockly

#10 Post by NetEye » 25 Aug 2018, 21:46

Hello grovkillen, thanks for your answer,
You mean Accu1 instead of Accu 1 and so on?
And which weblog viewer?
Thanks

User avatar
grovkillen
Core team member
Posts: 3621
Joined: 19 Jan 2017, 12:56
Location: Hudiksvall, Sweden
Contact:

Re: Rule/script or blockly

#11 Post by grovkillen » 25 Aug 2018, 22:02

Yes those ones. The web log viewer is found in the tools menu/page.
ESP Easy Flasher [flash tool and wifi setup at flash time]
ESP Easy Webdumper [easy screendumping of your units]
ESP Easy Netscan [find units]
Official shop: https://firstbyte.shop/
Sponsor ESP Easy, we need you :idea: :idea: :idea:

NetEye
Normal user
Posts: 51
Joined: 22 Jun 2016, 00:48

Re: Rule/script or blockly

#12 Post by NetEye » 25 Aug 2018, 22:59

Thank you, I will try it (never done it).
Still I hope toffel969 is willing to look at his changed rule.
Nice weekend

NetEye
Normal user
Posts: 51
Joined: 22 Jun 2016, 00:48

Re: Rule/script or blockly

#13 Post by NetEye » 26 Aug 2018, 09:49

Dear grovkillen,
Beside toffel969 I think you and others are also capable to review the changed rule.
Do you see any overcoming mistakes.
Is the whole section with the yellow highlighted required? (On Rules#timer=1 do pcfgpio,4,1 Endon)
When I run it again i will run the log.
Regards
Attachments
reviewed rule.png
reviewed rule.png (169.78 KiB) Viewed 16444 times
Last edited by NetEye on 26 Aug 2018, 10:08, edited 1 time in total.

User avatar
toffel969
Normal user
Posts: 469
Joined: 03 Jan 2017, 10:58
Location: Germany

Re: Rule/script or blockly

#14 Post by toffel969 » 26 Aug 2018, 10:04

NetEye wrote: 25 Aug 2018, 21:46 Hello grovkillen, thanks for your answer,
You mean Accu1 instead of Accu 1 and so on?
And which weblog viewer?
Thanks
Hi Neteye

On pcfgpio,4 or 7 --> of course you are right, I swapped IDX and port no.
I see there are more switch input devices on your node. Does each battery have their own relay? If yes you need to adapt the pcfgpio port to the respective battery in the rules.

On the timer you are generally correct as well, I dont know if there is an upper limit for that variable. Maybe TD-er or grovkillen can comment on that. A charge time of 24h seems a bit excessive ... I would go with 3600 as in 1h. Then the unit will charge for 1h, then stop to charge. If the voltage is then below threshold again charge agin for 1h. so on.

Spaces are indeed a common source of error in rules, so I can only underline what grovkillen is saying.
With weblog he means the log that you find under the tools tab -- log.
Domoticz on Raspi 2 -- 14 ESP units (hacked Sonoff,NodeMCUs, Wemos, self-built units) running with RC140- Mega 2.0.0 dev8

User avatar
toffel969
Normal user
Posts: 469
Joined: 03 Jan 2017, 10:58
Location: Germany

Re: Rule/script or blockly

#15 Post by toffel969 » 26 Aug 2018, 10:23

Just forget the comment about the 1h. With a 23V threshold it will only charge again if voltage drops below 23V. Thats not what you want. I will try to think about something better. or

There are a couple of voltages to distinguish :

V_min --> lower voltage where you would like to start charging
V_ok --> ok voltage, if you were charging, continue to charge. If you were consuming, continue to consume until you hit V_min
V_max --> stop charging

So when checking the voltage needs to know if it was charging or not.
It feels like a dummy device can help us in achieving that.
Maybe grovkillen (a little rules wizard , particularly when it comes to dummys and timers ) can help out here.


Another advice for you. Do not poll the I2C sensors every 1 s if not necessary (INAs on I2C). It makes the setup a lot more volatile than necessary. As a rule of thumb, as often as necessary, as few times as possible,
Domoticz on Raspi 2 -- 14 ESP units (hacked Sonoff,NodeMCUs, Wemos, self-built units) running with RC140- Mega 2.0.0 dev8

NetEye
Normal user
Posts: 51
Joined: 22 Jun 2016, 00:48

Re: Rule/script or blockly

#16 Post by NetEye » 26 Aug 2018, 11:20

Hi toffel969,
Quick answer, tanks, super.
About the switches, only switch4 operates all accus (via big diodes) the other switches are lights.
The 12V accus are the biggest to buy (230Ah each), so to get it full again a 24hrs load is needed (1hr is to short).
The minimum voltage limit I want is 23V so the rule has to start the load at 23V.
For the Vmax there is no limit needed, the charger is adjustable itself and also the diode arrange the charge.
(a Vmax is difficult to guess because off what TD-er said (the Voltage in rest is lower than when the charger is on).
I would like to handle it in time (all the years I use 24hrs in order of the supplier).
For the poll mentioned of the INA219, what delay time you advise...10sec?
Another question, on the first page I sended the "send boot state" is not marked, does it has to be check marked? (see picture).
This is fun, I have the feeling that you all will make it work.
Regards.
Attachments
relay with check mark.png
relay with check mark.png (189.22 KiB) Viewed 16436 times

User avatar
toffel969
Normal user
Posts: 469
Joined: 03 Jan 2017, 10:58
Location: Germany

Re: Rule/script or blockly

#17 Post by toffel969 » 26 Aug 2018, 11:31

Ok I think then you are fine with the 24h. Just try with that 86400 sec.

For the poll of the INA219, what delay time you advise...10sec?
How often does Domoticz actually log them ? 10 sec seems like a good start. It also depends a bit on what you do with the values.

Another question, on the first page I sended the "send boot state" is not marked, does it has to be check marked? (see picture).


This is fun, I have the feeling that you all will make it work.
Thats the real beauty of the ESP Easy community here. I received a lot of help from people on this forum, more than you can ever expect.


[/quote]
Domoticz on Raspi 2 -- 14 ESP units (hacked Sonoff,NodeMCUs, Wemos, self-built units) running with RC140- Mega 2.0.0 dev8

NetEye
Normal user
Posts: 51
Joined: 22 Jun 2016, 00:48

Re: Rule/script or blockly

#18 Post by NetEye » 26 Aug 2018, 11:50

Hello toffel969,
You forgot to answer in the rush about the check mark, hahaha, does it has to be check marked or not?
So the rule I test today will be like the picture (i don't know how to make a window wit "code: select all" ).
- just changed the start action to 1 instead of 0.
Does the "Endon" action in the rule set the switch value to "0"?
* When i would like to built another rule in the same ESP can I just write it below the other?
* And what if the INA and the switch where on a different ESP...how ould the rule be like?
(last two questions only for nice to know and to learn).
Yes this forum is fantastic and useful
Regards
Attachments
reviewed rule.png
reviewed rule.png (140.46 KiB) Viewed 16427 times

NetEye
Normal user
Posts: 51
Joined: 22 Jun 2016, 00:48

Re: Rule/script or blockly

#19 Post by NetEye » 26 Aug 2018, 14:25

Hi Toffel969,
I implemented the changed rule whiteout the yellow highlighted part.
The charger starts at the given voltage value (slightly changed for test) but its does not stop at the given time (also slightly changed for the test).
Is it possible that the yellow highlighted part needs to be in too to give the close value "0" to switch4?
Probably in only slightly change the "Rules#timer=1 that will forse it now to stop after 10 minutes instead of 24hrs.
I feel we are almost there ;)
regards
Attachments
reviewed rule with yellow Highlighted part.png
reviewed rule with yellow Highlighted part.png (169.79 KiB) Viewed 16409 times

NetEye
Normal user
Posts: 51
Joined: 22 Jun 2016, 00:48

Re: Rule/script or blockly

#20 Post by NetEye » 27 Aug 2018, 09:31

Hi Toffel969 or others,
Just for test I have entered the yellow highlighted part (because of the pcfgpio,4,0 value).
Only one question about it.
When starts the 10 minutes counting in that part (isn’t it conflicting with the rest?).
Regards
Last edited by NetEye on 27 Aug 2018, 09:46, edited 1 time in total.

User avatar
toffel969
Normal user
Posts: 469
Joined: 03 Jan 2017, 10:58
Location: Germany

Re: Rule/script or blockly

#21 Post by toffel969 » 27 Aug 2018, 09:36

NetEye wrote: 26 Aug 2018, 14:25 Hi Toffel969,
I implemented the changed rule whiteout the yellow highlighted part.
The charger starts at the given voltage value (slightly changed for test) but its does not stop at the given time (also slightly changed for the test).
Is it possible that the yellow highlighted part needs to be in too to give the close value "0" to switch4?
Probably in only slightly change the "Rules#timer=1 that will forse it now to stop after 10 minutes instead of 24hrs.
I feel we are almost there ;)
regards
Hi Neteye

Endon terminates a rule. Without it, ESPEasy doesnt know where a rule stops and you will see all sorts of funny behaviour.

Rules#timer=1 is an event that is triggered when timer 1 elapses. Without that statement, nothing will happen after the 86400 sec --> it will never stop charging. Of course it needs to be pcfgpio,4,0 that's a logic consequence of the earlier mistake.

about different units, yes is definitly possible in more than one way.

In order to grow with the rules you definitly need to study the tutorial, it sums everything up very nicely. Also try to get the notepad++ layout from grovkillen to check for syntax errors.
https://www.letscontrolit.com/wiki/inde ... rial_Rules

check this section in particular for the remote part https://www.letscontrolit.com/wiki/inde ... #HTTP_call

If you still get stuck with something get back to the forum
Domoticz on Raspi 2 -- 14 ESP units (hacked Sonoff,NodeMCUs, Wemos, self-built units) running with RC140- Mega 2.0.0 dev8

NetEye
Normal user
Posts: 51
Joined: 22 Jun 2016, 00:48

Re: Rule/script or blockly

#22 Post by NetEye » 27 Aug 2018, 10:07

Toffel969,
Thanks for your help, I will enter your first rule in detail with changed values (you checked if it produces syntax errors?)
I will look for the notepad++ layout (a new challenge).
I will study the userguide thoroughly.
Thanks again,

NetEye
Normal user
Posts: 51
Joined: 22 Jun 2016, 00:48

Re: Rule/script or blockly

#23 Post by NetEye » 27 Aug 2018, 12:24

The rule works, it starts en stops in the given values.
Bravo.

NetEye
Normal user
Posts: 51
Joined: 22 Jun 2016, 00:48

Re: Rule/script or blockly

#24 Post by NetEye » 26 Sep 2019, 17:59

Dear Toffel,
The rule works 100% perfect, thanks.
Now I want to send or read data from one device to another, I hope you will help me again with this.
On ESP1 (DigiDash 1) I have "Accu1" = Task 8 and "Accu2" = Task 9 (192.168.3.104)
On ESP3 (DigiDash 3) I have "Accu keuze 1 of 2" = Task 5 (192.168.3.107)
When "Accu1" has a value of for instance 22.5V on ESP1 its has to switch "Accu keuze 1 of 2" on ESP3 (DigiDash 3) to 1.
And when "Accu2" has a value of for instance 22.5V on ESP1 its has to switch "Accu keuze 1 of 2" on ESP3 (DigiDash 3) to 0.
Wit searching in the tutorial I made (Maybe you can correct it or complete it).
Switch to 1:
On ESP1 rule:

on Accu1#Voltage=22.5 do
SendToHTTP 192.168.3.107,80,/control?cmd=event, Accu keuze 1 of 2 ?????command?????
endon

On ESP3 rule:

on Accu keuze 1 of 2 ?????command????? do
pcfgpio,67,1 //Accu keuze 1 of 2 switch naar 1, and 67 stands for ESPEasy port nr
endon



Switch to back to 0:

On ESP1 rule:

on Accu2#Voltage=22.5 do
SendToHTTP 192.168.3.107,80,/control?cmd=event, Accu keuze 1 of 2 ?????command?????
endon

On ESP3 rule:

on Accu keuze 1 of 2 ?????command????? do
pcfgpio,67,0 //Accu keuze 1 of 2 switch naar 0, and 67 stands for ESPEasy port nr
endon


If this works I want also do something with Gell accu 3 (calls now: "Accu3"), I then want him to switch another switch on ESP3 (that's for later ;-) )

I hope you can help me with the commands, because you helped me super with the last.

NetEye
Attachments
5 devices.PNG
5 devices.PNG (428.63 KiB) Viewed 14401 times
5 devices.png
5 devices.png (276.74 KiB) Viewed 14401 times
6 devices.png
6 devices.png (297.81 KiB) Viewed 14401 times

NetEye
Normal user
Posts: 51
Joined: 22 Jun 2016, 00:48

Re: Rule/script or blockly

#25 Post by NetEye » 27 Sep 2019, 14:26

NetEye wrote: 26 Sep 2019, 17:59 Dear Toffel,
The rule works 100% perfect, thanks.
Now I want to send or read data from one device to another, I hope you will help me again with this.
On ESP1 (DigiDash 1) I have "Accu1" = Task 8 and "Accu2" = Task 9 (192.168.3.104)
On ESP3 (DigiDash 3) I have "Accu keuze 1 of 2" = Task 5 (192.168.3.107)
When "Accu1" has a value of for instance 22.5V on ESP1 its has to switch "Accu keuze 1 of 2" on ESP3 (DigiDash 3) to 1.
And when "Accu2" has a value of for instance 22.5V on ESP1 its has to switch "Accu keuze 1 of 2" on ESP3 (DigiDash 3) to 0.
Wit searching in the tutorial I made (Maybe you can correct it or complete it).

Switch to 1:

On ESP1 rule:

on Accu1#Voltage=22.5 do
SendToHTTP 192.168.3.107,80,/control?cmd=event, Accu keuze 1 of 2 ?????command?????
endon


On ESP3 rule:

on Accu keuze 1 of 2 ?????command????? do
pcfgpio,67,1 //Accu keuze 1 of 2 switch naar 1, and 67 stands for ESPEasy port nr
endon



Switch to back to 0:

On ESP1 rule:

on Accu2#Voltage=22.5 do
SendToHTTP 192.168.3.107,80,/control?cmd=event, Accu keuze 1 of 2 ?????command?????
endon


On ESP3 rule:

on Accu keuze 1 of 2 ?????command????? do
pcfgpio,67,0 //Accu keuze 1 of 2 switch naar 0, and 67 stands for ESPEasy port nr
endon


If this works I want also do something with Gell accu 3 (calls now: "Accu3"), I then want him to switch another switch on ESP3 (that's for later ;-) )

I hope you can help me with the commands, because you helped me super with the last.

NetEye

Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot] and 28 guests