run bash-script on boiler status

Moderator: leecollings

Post Reply
rolfb
Posts: 14
Joined: Wednesday 26 September 2018 16:50
Target OS: Raspberry Pi / ODroid
Domoticz version: 4.10717
Contact:

run bash-script on boiler status

Post by rolfb »

Hi all,

I'm fairly new, and my first attempt on doing something else with Domo then monitoring. Please be patient...

I've setup latest stable version, and have included successfully my Nefit easy thermostat. I am able to see the "boiler status" in my webGUI.
When looking at the log of that item, it reads:

Code: Select all

2019-06-15 16:35:49	off
2019-06-15 16:34:45	hot water
2019-06-15 16:24:38	off
2019-06-15 16:23:35	hot water
I am trying to make a bash-script run when boiler status is "hot water" (ultimately to have a notification of any kind when the shower is running too long
:twisted: )

So I've created a blockly script saying:

Code: Select all

If [boiler status ] text = "hot water" 
do start script /home/pi/test.sh with params <empty>
bash script is executable, and when started by hand from commandline works.
However, when turning on the hot water, I see the status of this item change to ' hot water' (in the webGUI) after some time, but my script is not executed.
The log of Domo (GUI) says nothing when testing this script.
Am I making a mistake here? Do I want something that is not possible?
Please help/advice?

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

Re: run bash-script on boiler status

Post by waaren »

rolfb wrote: Saturday 15 June 2019 16:49 I've setup latest stable version, and have included successfully my Nefit easy thermostat. I am able to see the "boiler status" in my webGUI.
I am trying to make a bash-script run when boiler status is "hot water" (ultimately to have a notification of any kind when the shower is running too long
bash script is executable, and when started by hand from commandline works.
However, when turning on the hot water, I see the status of this item change to ' hot water' (in the webGUI) after some time, but my script is not executed.
The log of Domo (GUI) says nothing when testing this script.
Best to attach a screenshot of your Blockly. Is it set as Active and as Device triggered ?
I assume the device is a Text device. Can you please confirm.
Is the script executable for the domoticz user ?
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
rolfb
Posts: 14
Joined: Wednesday 26 September 2018 16:50
Target OS: Raspberry Pi / ODroid
Domoticz version: 4.10717
Contact:

Re: run bash-script on boiler status

Post by rolfb »

Hi,
yes, it is a text device, see below.
Domo runs under user pi, and script is executable for it:

Code: Select all

pi@titanium:~ $ pwd
/home/pi
pi@titanium:~ $ ls -l test*
-rwxr-xr-x 1 pi pi 24 Jun 15 16:18 test.sh
Is my assumption correct that in a text-devince, I should enter the exact text as is displayed in the status/history of the device?
Attachments
nefit-blockly.png
nefit-blockly.png (51.16 KiB) Viewed 1549 times
rolfb
Posts: 14
Joined: Wednesday 26 September 2018 16:50
Target OS: Raspberry Pi / ODroid
Domoticz version: 4.10717
Contact:

Re: run bash-script on boiler status

Post by rolfb »

Further testing reveals both statements (if & do) contain something wrong.
(when splitting i and replacing parts with working code, both fail).

As for the if statement: where to look for the exact text after the = sign?
On the small tab "devices current states", there are 2 columns: state and value. They contain "hot water", and "0/hot water". Both do not work when entered in the blockly statement. Is there another place to look for the exact text to enter? Can I use a wildcard here or a 'contains' statement?

As for the execution of the script:
when executing a script when I turn on a light, in the log I see the script is triggered:

Code: Select all

2019-06-16 14:52:58.815 Status: User: rolf initiated a switch command (3/Bulb bol/On)
2019-06-16 14:52:58.890 Status: ===bashtest===
2019-06-16 14:52:59.092 Status: Executing script: /home/pi/test.sh
But on the OS, nothing happens...
(earlier I said domois running as pi, but ps -ef tails me it's running as daemon under root.
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: run bash-script on boiler status

Post by waaren »

rolfb wrote: Sunday 16 June 2019 11:34 Hi,
yes, it is a text device, see below.
Domo runs under user pi, and script is executable for it:

Code: Select all

pi@titanium:~ $ pwd
/home/pi
pi@titanium:~ $ ls -l test*
-rwxr-xr-x 1 pi pi 24 Jun 15 16:18 test.sh
Is my assumption correct that in a text-device, I should enter the exact text as is displayed in the status/history of the device?
I am not an expert with Blockly but I tested this in every way I could think of and there was no way I could trigger the Blockly condition if I set the condition like any of the following
  • = "hot water"
  • = "hot+water"
  • = "hot%20water"
if I try with unequal, the Blockly triggers the condition but it does so for every string So it triggers for unequal to "hot water" but also for unequal to "cold" and also for unequal to "off"
When I use the block with the text content in a log statement then it returns the expected value.
My conclusion from the above testing is that you cannot use the value from the text sensor to trigger the Blockly condition.

Tried the same with a dzVents script and that works as expected. Tried to search in the domoticz source code (main/EventSystem.cpp) to find if I could identify the difference between Blockly and dzVents for this but have not found anything yet.

dzVents script (textTrigger.lua)

Code: Select all

return {    on = { devices = { 'Boiler status' }},
            logging = { level = domoticz.LOG_DEBUG, marker = 'text trigger'},

    execute = function(dz, item )
        dz.log(item.name .. ' ==>> ' .. item.text,dz.LOG_DEBUG)
        if item.text == 'hot water' then
            os.execute("/home/pi/test.sh 'hot water' ")
        else
            os.execute("/home/pi/test.sh 'cold' ")
        end
    end
}
domoticz log

Code: Select all

2019-06-16 15:12:22.761  Status: dzVents: Info:  Handling events for: "Boiler status", value: "cold"
2019-06-16 15:12:22.762  Status: dzVents: Info:  text trigger: ------ Start external script: textTrigger.lua: Device: "Boiler status (Virtual)", Index: 2135
2019-06-16 15:12:22.764  Status: dzVents: Debug: text trigger: Boiler status ==>> cold
2019-06-16 15:12:22.795  Status: dzVents: Info:  text trigger: ------ Finished textTrigger.lua

2019-06-16 15:12:35.602  Status: dzVents: Info:  Handling events for: "Boiler status", value: "hot water"
2019-06-16 15:12:35.603  Status: dzVents: Info:  text trigger: ------ Start external script: textTrigger.lua: Device: "Boiler status (Virtual)", Index: 2135
2019-06-16 15:12:35.604  Status: dzVents: Debug: text trigger: Boiler status ==>> hot water
2019-06-16 15:12:35.634  Status: dzVents: Info:  text trigger: ------ Finished textTrigger.lua
/home/pi/test.sh

Code: Select all

#!/bin/bash

echo $(date) $@ >>  /home/pi/test.log
/home/pi/test.log

Code: Select all

Sun 16 Jun 15:12:22 CEST 2019 cold
Sun 16 Jun 15:12:35 CEST 2019 hot water
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
rolfb
Posts: 14
Joined: Wednesday 26 September 2018 16:50
Target OS: Raspberry Pi / ODroid
Domoticz version: 4.10717
Contact:

Re: run bash-script on boiler status

Post by rolfb »

thanks for helping me out.
I am not familiar with dzvents scripts. Should your above code-sample work on my Domo? (Because it does not...)
Is the most basic version:

Code: Select all

return {    on = { devices = { 'Boiler status' }},
           
    execute = function(dz, item )
                if item.text == 'hot water' then
            os.execute("/home/pi/test.sh 'hot water' ")
    end
end    
}
?
When is this event run? I can't see that in the code?
Sorry for my possibly newby questions...

(the bash-part is solved: I made a script to echo `date` into test.txt, but did not specify a location for that file, so it ended up in /home/pi/domoticz, not in /home/pi...)
rolfb
Posts: 14
Joined: Wednesday 26 September 2018 16:50
Target OS: Raspberry Pi / ODroid
Domoticz version: 4.10717
Contact:

Re: run bash-script on boiler status

Post by rolfb »

OK, some steps further.
I've recreated your setup with a virtual text device, and that works with the script you provided.
After that, I used a jsoncall in the browser to change the status of my real device to 'hot water' (this whole thing was ultimately to save on gas, but I've put on the hot tap many times today... :shock: ) and then the script ran on my real device.
However, the status is not put back by the real Nefit to off...
I'm looking into that right now. (maybe one more time turn on and off the hot tap...)

I think maybe there is some non-displayed character in the status, as updated by Nefit. Is it possible to use a wildcard, or a 'like' statement in the script?
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: run bash-script on boiler status

Post by waaren »

rolfb wrote: Sunday 16 June 2019 17:46 I think maybe there is some non-displayed character in the status, as updated by Nefit. Is it possible to use a wildcard, or a 'like' statement in the script?
When not yet familiar with dzVents please start with reading Get started Before implementing. Special attention please for
"In Domoticz go to Setup > Settings > Other and in the section EventSystem make sure the checkbox 'dzVents disabled' is not checked. Also make sure that in the Security section in the settings you allow 127.0.0.1 to not need a password. dzVents uses that port to send certain commands to Domoticz. Finally make sure you have set your current location in Setup > Settings > System > Location, otherwise there is no way to determine nighttime/daytime state."

Try it with this.

Code: Select all

return {    on = { devices = { 'Boiler status' }}, -- the device with this name triggers the script on update
            logging = { level = domoticz.LOG_DEBUG, marker = 'text trigger'},

    execute = function(dz, item )
        dz.log(item.name .. ' ==>> ' .. item.text,dz.LOG_DEBUG)
        if (item.text):match('hot') then -- Looking for this string in the text.
            dz.log(item.name .. '.text ==>> contains the word "hot"',dz.LOG_DEBUG)
            os.execute("/home/pi/test.sh 'hot water' ")
        else
            dz.log(item.name .. '.text ==>> does not contain the word "hot"',dz.LOG_DEBUG)
            os.execute("/home/pi/test.sh 'cold' ")
        end
    end
}
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
rolfb
Posts: 14
Joined: Wednesday 26 September 2018 16:50
Target OS: Raspberry Pi / ODroid
Domoticz version: 4.10717
Contact:

Re: run bash-script on boiler status

Post by rolfb »

It now works.
It looks like this value had to be initialized via a jsoncall first, and then the flow works:

Code: Select all

2019-06-17 06:30:08.091 Status: dzVents: Debug: text trigger: BoilerStatus ==>> hot water
2019-06-17 06:32:13.909 Status: dzVents: Debug: text trigger: BoilerStatus ==>> off
2019-06-17 06:57:48.005 Status: dzVents: Debug: text trigger: BoilerStatus ==>> hot water
2019-06-17 07:07:11.848 Status: dzVents: Debug: text trigger: BoilerStatus ==>> off
2019-06-17 07:10:50.138 Status: dzVents: Debug: text trigger: BoilerStatus ==>> hot water
2019-06-17 07:13:07.790 Status: dzVents: Debug: text trigger: BoilerStatus ==>> off
2019-06-17 07:14:42.070 Status: dzVents: Debug: text trigger: BoilerStatus ==>> hot water
2019-06-17 07:15:44.734 Status: dzVents: Debug: text trigger: BoilerStatus ==>> off
2019-06-17 07:16:15.962 Status: dzVents: Debug: text trigger: BoilerStatus ==>> hot water
2019-06-17 07:16:47.199 Status: dzVents: Debug: text trigger: BoilerStatus ==>> off
2019-06-17 07:20:26.617 Status: dzVents: Debug: text trigger: BoilerStatus ==>> hot water
2019-06-17 07:28:49.093 Status: dzVents: Debug: text trigger: BoilerStatus ==>> off
(not all intervalls are actually showering: the boiler keeps water at temp in the morning for convenience.)
Now the fun part can start: think of notifications I will start when my children are in the shower too long. :twisted:
Thanks for all the help!
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest