Pass2PHP

Moderator: leecollings

Trigun
Posts: 390
Joined: Wednesday 30 November 2016 11:58
Target OS: Raspberry Pi / ODroid
Domoticz version: 4.10717
Contact:

Re: Pass2PHP

Post by Trigun »

Egregius wrote: Wednesday 01 July 2020 10:27 Do you have your timezone set in your php.ini?

in /etc/php/7.3/fpm

Code: Select all

[Date]
; Defines the default timezone used by the date functions
; http://php.net/date.timezone
date.timezone = 'Europe/Brussels'
I've changed this but for some reason it doesn't change.

when I check my php config I still see the default:
2020-07-01 10_42_07-PHP 7.3.14-1~deb10u1 - phpinfo().png
2020-07-01 10_42_07-PHP 7.3.14-1~deb10u1 - phpinfo().png (13.43 KiB) Viewed 1635 times
2020-07-01 10_41_39-PHP 7.3.14-1~deb10u1 - phpinfo().png
2020-07-01 10_41_39-PHP 7.3.14-1~deb10u1 - phpinfo().png (16.79 KiB) Viewed 1635 times
am I doing something wrong?
User avatar
Egregius
Posts: 2582
Joined: Thursday 09 April 2015 12:19
Target OS: Linux
Domoticz version: v2024.7
Location: Beitem, BE
Contact:

Re: Pass2PHP

Post by Egregius »

did you restart the php fpm service to load the new ini?

Code: Select all

service php7.3-fpm restart
Trigun
Posts: 390
Joined: Wednesday 30 November 2016 11:58
Target OS: Raspberry Pi / ODroid
Domoticz version: 4.10717
Contact:

Re: Pass2PHP

Post by Trigun »

Really?? I restarted NGINX but that didn't do the trick haha :D
thanks, this works!

hopefully the time script will work better now.
Keep you posted
Trigun
Posts: 390
Joined: Wednesday 30 November 2016 11:58
Target OS: Raspberry Pi / ODroid
Domoticz version: 4.10717
Contact:

Re: Pass2PHP

Post by Trigun »

I've tested with this script:

Code: Select all

<?php
if ($status=='On') {
	if (TIME<=strtotime('8:00')) {
		sl('Overloop', 0);} 
elseif (TIME>=strtotime('8:00') || TIME<=strtotime('10:30')) {
		sl('Overloop', 100);} 
else {
sl('Overloop', 30);}

}
I can test it quickly since the PIR is close by.
"Overloop" does change to 100% but after setting the time to earlier than it is now, it does not change to 30% as it is 11:15 now and should be the "else" part of the script
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: Pass2PHP

Post by waaren »

Egregius wrote: Wednesday 01 July 2020 10:30 Indeed, they're executed sequentially. For example: first all blocklies, then all dzvents, then all python, then all lua scripts.
That is not how the eventSystem works. Blockly, classic Lua and dzVents are all Lua scripts for the eventSystem. From the perspective of the domoticz eventSystem there is only one dzVents script: dzVents.lua
That's because all scripts are executed on every device update and you filter the device in the script itself.
Again that is not how dzVents work.
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
Trigun
Posts: 390
Joined: Wednesday 30 November 2016 11:58
Target OS: Raspberry Pi / ODroid
Domoticz version: 4.10717
Contact:

Re: Pass2PHP

Post by Trigun »

But domoticz does handle them in an order right? and thats the case here
User avatar
Egregius
Posts: 2582
Joined: Thursday 09 April 2015 12:19
Target OS: Linux
Domoticz version: v2024.7
Location: Beitem, BE
Contact:

Re: Pass2PHP

Post by Egregius »

What happens if you add for example this:?

Code: Select all

lg(strftime("%H:%M", strtotime('11:00')));
User avatar
Egregius
Posts: 2582
Joined: Thursday 09 April 2015 12:19
Target OS: Linux
Domoticz version: v2024.7
Location: Beitem, BE
Contact:

Re: Pass2PHP

Post by Egregius »

And I just saw an error:

Code: Select all

<?php
if ($status=='On') {
	if (TIME<=strtotime('8:00')) {
		sl('Overloop', 0);} 
elseif (TIME>=strtotime('8:00') || TIME<=strtotime('10:30')) {
		sl('Overloop', 100);} 
else {
sl('Overloop', 30);}

}
should be:

Code: Select all

<?php
if ($status=='On') {
	if (TIME<strtotime('8:00')) {
		sl('Overloop', 0);
	} elseif (TIME>=strtotime('8:00') && TIME<=strtotime('10:30')) {
		sl('Overloop', 100);
	} else {
		sl('Overloop', 30);
	}
}
User avatar
Egregius
Posts: 2582
Joined: Thursday 09 April 2015 12:19
Target OS: Linux
Domoticz version: v2024.7
Location: Beitem, BE
Contact:

Re: Pass2PHP

Post by Egregius »

waaren wrote: Wednesday 01 July 2020 11:19
Egregius wrote: Wednesday 01 July 2020 10:30 Indeed, they're executed sequentially. For example: first all blocklies, then all dzvents, then all python, then all lua scripts.
That is not how the eventSystem works. Blockly, classic Lua and dzVents are all Lua scripts for the eventSystem. From the perspective of the domoticz eventSystem there is only one dzVents script: dzVents.lua
That's because all scripts are executed on every device update and you filter the device in the script itself.
Again that is not how dzVents work.
That's not how I understand the wiki at https://www.domoticz.com/wiki/DzVents:_ ... .80.A6_.7D
From that my understanding is that all dzvents scripts need to be parsed in order to find if something has to be done or not.
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: Pass2PHP

Post by waaren »

Egregius wrote: Wednesday 01 July 2020 13:44 That's not how I understand the wiki at https://www.domoticz.com/wiki/DzVents:_ ... .80.A6_.7D
From that my understanding is that all dzvents scripts need to be parsed in order to find if something has to be done or not.
Thank you for showing interest in the internals of dzVents.

the dzVents user script are in fact all modules of the main dzVents.lua. The loading of these userscript is therefore under control of the Lua cache mechanism. In these modules is a collection of tables / functions; one of them being the on table , which can contain a devices table which is interpreted by EventHelpers.lua. No user scripts are parsed to domoticz. They are all processed within the control of the one dzVents.lua.

The whole process is designed to prevent the need that all scripts are to be executed on every device change and every time trigger. The only communication back to domoticz is via the commandArray.

Happy to explain in more detail if you want.
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
Trigun
Posts: 390
Joined: Wednesday 30 November 2016 11:58
Target OS: Raspberry Pi / ODroid
Domoticz version: 4.10717
Contact:

Re: Pass2PHP

Post by Trigun »

Egregius wrote: Wednesday 01 July 2020 11:43 And I just saw an error:
I Changed is and it seems to work now!

thanks a lot!
Trigun
Posts: 390
Joined: Wednesday 30 November 2016 11:58
Target OS: Raspberry Pi / ODroid
Domoticz version: 4.10717
Contact:

Re: Pass2PHP

Post by Trigun »

Hi Guys,

quick question.

I want to activate a Node-red flow with domoticz.
is there a chance anyone can tell me how to switch a light from domoticz which activates a Node-Red flow.

there are a lot of topics that show to control a switch from node-red to domoticz but I can't find a way to switch a light from domoticz to a node-red flow.

thanks a lot!

cheers!
User avatar
Egregius
Posts: 2582
Joined: Thursday 09 April 2015 12:19
Target OS: Linux
Domoticz version: v2024.7
Location: Beitem, BE
Contact:

Re: Pass2PHP

Post by Egregius »

Any chance you can trigger it from within PHP?
Otherwise, sorry, 0 experience with node-red.
Trigun
Posts: 390
Joined: Wednesday 30 November 2016 11:58
Target OS: Raspberry Pi / ODroid
Domoticz version: 4.10717
Contact:

Re: Pass2PHP

Post by Trigun »

Egregius wrote:Any chance you can trigger it from within PHP?
Otherwise, sorry, 0 experience with node-red.
Possibly(which is my preferred way) but don’t know howImage


Sent from my iPhone using Tapatalk
ropske
Posts: 483
Joined: Tuesday 12 August 2014 5:37
Target OS: Raspberry Pi / ODroid
Domoticz version: V3_8394
Location: Rumbeke,Belgium
Contact:

Re: Pass2PHP

Post by ropske »

Trigun wrote: Friday 18 September 2020 20:26
Egregius wrote:Any chance you can trigger it from within PHP?
Otherwise, sorry, 0 experience with node-red.
Possibly(which is my preferred way) but don’t know howImage


Sent from my iPhone using Tapatalk

i've got it working mate in nodered; but i use it to say a text from php to my google home mini's; but i changed it to use without for you

Code: Select all

[{"id":"1523f5d1.d76ada","type":"http in","z":"2133ab40.3b8894","name":"testje","url":"/hello-form","method":"post","upload":false,"swaggerDoc":"","x":130,"y":1460,"wires":[["688e7e73.c4785"]]},{"id":"8d943de9.da48d","type":"debug","z":"2133ab40.3b8894","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":570,"y":1460,"wires":[]},{"id":"688e7e73.c4785","type":"change","z":"2133ab40.3b8894","name":"","rules":[{"t":"set","p":"message","pt":"msg","to":"payload.name","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":330,"y":1460,"wires":[["8a0699e7.9a1728","8d943de9.da48d"]]}]
and then in php i use curl:

Code: Select all

curl -X POST -d "name=testje" http://192.168.1.143:1880/hello-form
where 192.168.1.143:1880 is where my node-red is running of course
Last edited by ropske on Sunday 20 September 2020 12:59, edited 3 times in total.
ropske
Posts: 483
Joined: Tuesday 12 August 2014 5:37
Target OS: Raspberry Pi / ODroid
Domoticz version: V3_8394
Location: Rumbeke,Belgium
Contact:

Re: Pass2PHP

Post by ropske »

because i wanted to try the Egrerius way, but i'm not able to get it work :lol:

Code: Select all

function speakToGoogleMini($msg)
{
	$data='name='.$msg;
	
	$ch = curl_init();
	$url = "http://192.168.1.143:1880/hello-form";
	curl_setopt($ch,CURLOPT_URL,$url);
	curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
	curl_setopt($ch, CURLOPT_POST, 1);		//0 is GET
	curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
		
	$response=curl_exec($ch);
	curl_close($ch);
}
and then calling:

Code: Select all

speakToGoogleMini('testje om te proberen');
but nothing happens :o

the 'name=' i need to use in curl, because i need it in node-red
Last edited by ropske on Sunday 20 September 2020 13:01, edited 1 time in total.
ropske
Posts: 483
Joined: Tuesday 12 August 2014 5:37
Target OS: Raspberry Pi / ODroid
Domoticz version: V3_8394
Location: Rumbeke,Belgium
Contact:

Re: Pass2PHP

Post by ropske »

if i put a 'debug node' on node-red, it seems my action is not triggered at the input side.
User avatar
Egregius
Posts: 2582
Joined: Thursday 09 April 2015 12:19
Target OS: Linux
Domoticz version: v2024.7
Location: Beitem, BE
Contact:

Re: Pass2PHP

Post by Egregius »

I set the url slightly different for curl, I also set a content-type.

Code: Select all

function kodi($json)
{
    global $kodiurl;
    $ch=curl_init($kodiurl.'/jsonrpc');
    curl_setopt($ch, CURLOPT_POST, 1);
    curl_setopt($ch, CURLOPT_POSTFIELDS, $json);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json'));
    $result=curl_exec($ch);
    curl_close($ch);
    return $result;
}

function bosepost($method,$xml,$ip=101,$log=false)
{
    global $user;
    for($x=1;$x<=100;$x++) {
		$ch=curl_init("http://192.168.2.$ip:8090/$method");
		curl_setopt($ch, CURLOPT_POST, 1);
		curl_setopt($ch, CURLOPT_POSTFIELDS, $xml);
		curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
		curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/xml'));
		$response=curl_exec($ch);
		curl_close($ch);
		if ($response=='<?xml version="1.0" encoding="UTF-8" ?><status>/'.$method.'</status>') break;
		usleep(100000);
	}
    return $response;
}
Trigun
Posts: 390
Joined: Wednesday 30 November 2016 11:58
Target OS: Raspberry Pi / ODroid
Domoticz version: 4.10717
Contact:

Re: Pass2PHP

Post by Trigun »

ok, Iam quite new to node red so therefore thanks for your reply but I have no idea where to start.

the situation is as following:

within node-red there is a way to control your samsung TV.
I would like to have some virtual buttons which can trigger a node-red flow.
for example. when I press the button, my samsung TV will turn On. and obviously many more triggers will be possible.

unfortunately I have no idea how to start from a virtual switch to triggering a node-red flow.
is this done via a script perhaps?

hope you guys can help me out.

ps. when I enter the following in cmd:

Code: Select all

mosquitto_pub -h vm-domoticz.home.local -t "domoticz/in" -m '{ "idx" : 202, "nvalue" : 0}'
the switch in domoticz turns Off. but this is the other way around. I would like to switch the button and see in the debug mode that de switch is triggerd. hopefully this makes it a bit more clearer.

thanks in advance!
ropske
Posts: 483
Joined: Tuesday 12 August 2014 5:37
Target OS: Raspberry Pi / ODroid
Domoticz version: V3_8394
Location: Rumbeke,Belgium
Contact:

Re: Pass2PHP

Post by ropske »

when i also use a header like you Egrerius, it still does not work:

Code: Select all

function speakToGoogleMini($msg)
{
	$jsonString = json_encode(array("text" => "testje"));

	// You can directly replace your JSON string with $jsonString variable.
	$ch = curl_init('http://192.168.1.143/hello-form');
	curl_setopt($ch, CURLOPT_PORT, 1880);
    curl_setopt($ch, CURLOPT_POST, 1);
	curl_setopt($ch, CURLOPT_POSTFIELDS, $jsonString);
	curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
	curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json'));
	$result = curl_exec($ch);
	curl_close($ch);
}
it does not reach my node-red input.

put when i do this in command line:

Code: Select all

curl -X POST -d "name=testje" http://192.168.1.143:1880/hello-form
it is reaching my node-red input

so i don't know what i'm doing wrong for the moment

@Trigun, i will come back to you tonight to help you with the node-red
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest