Pass2PHP

Moderator: leecollings

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 »

Trigun wrote: Tuesday 07 May 2019 12:26 I tried sudo crontab -e and entered the same line and this seems to work.
strange! is there a difference between the two different crontabs?
I never used nano to edit the crontab, don't know if that's working.
I always use crontab -e and never had issues (except stupid mistakes ;) )
User avatar
sincze
Posts: 1300
Joined: Monday 02 June 2014 22:46
Target OS: Raspberry Pi / ODroid
Domoticz version: 2024.4
Location: Netherlands / Breda Area
Contact:

Re: Pass2PHP

Post by sincze »

Our IT department gave me the instrument of
sudo nano /etc/crontab

Have been using it ever since
Rest assure it works perfectly :D
Pass2php
LAN: RFLink, P1, OTGW, MySensors
USB: RFXCom, ZWave, Sonoff 3
MQTT: ZIgbee2MQTT,
ZWAVE: Zwave-JS-UI
WIFI: Mi-light, Tasmota, Xiaomi Shelly
Solar: Omnik, PVOutput
Video: Kodi, Harmony HUB, Chromecast
Sensors: You name it I got 1.
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 get different contents with nano /etc/crontab and with crontab -e :?
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:I get different contents with nano /etc/crontab and with crontab -e :?
Ah sometimes its good to hear its not only meImageImage. I never knew there were different crontab possibilities

So far sudo crontab -e works good


Sent from my iPhone using Tapatalk
User avatar
sincze
Posts: 1300
Joined: Monday 02 June 2014 22:46
Target OS: Raspberry Pi / ODroid
Domoticz version: 2024.4
Location: Netherlands / Breda Area
Contact:

Re: Pass2PHP

Post by sincze »

Hahaha.
I have no clue I just work here.
If it works it works.

I had issues with the crontab -e so started to complain at the IT department. The old Linux system administrator came up with the 'golden' Idea and helped me.

Linux has more roads to Rome so it seems.
Pass2php
LAN: RFLink, P1, OTGW, MySensors
USB: RFXCom, ZWave, Sonoff 3
MQTT: ZIgbee2MQTT,
ZWAVE: Zwave-JS-UI
WIFI: Mi-light, Tasmota, Xiaomi Shelly
Solar: Omnik, PVOutput
Video: Kodi, Harmony HUB, Chromecast
Sensors: You name it I got 1.
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 »

He Guys,

stil working on the light going out :?
since I want both the "Bijkeuken" and the "Garageportaal" to go out after 60 seconds I did the following.
created the device scripts --> these work and the lights are going on.
within the _cron60 script I put in the following.

Code: Select all

<?php
$items=array('Bijkeuken','Garageportaal');
foreach ($items as $item)
    if ($d['$item']['s']=='On'
    && past('$item')>60) {
    sw('$item', 'Off');
    lg('_cron60test');
}
?>
but in the apache log i get the following error:

Code: Select all

[Wed May 08 13:19:01.596234 2019] [:error] [pid 676] [client 127.0.0.1:33746] PHP Notice:  Undefined index: item in /var/www/html/secure/_cron60.php on line 4
Based on the output I'm guessing I have to define the "items" somewhere. but where am I doing that?
User avatar
sincze
Posts: 1300
Joined: Monday 02 June 2014 22:46
Target OS: Raspberry Pi / ODroid
Domoticz version: 2024.4
Location: Netherlands / Breda Area
Contact:

Re: Pass2PHP

Post by sincze »

Not necessary. Check the sw function it can handle arrays already. Use that instead :)
Pass2php
LAN: RFLink, P1, OTGW, MySensors
USB: RFXCom, ZWave, Sonoff 3
MQTT: ZIgbee2MQTT,
ZWAVE: Zwave-JS-UI
WIFI: Mi-light, Tasmota, Xiaomi Shelly
Solar: Omnik, PVOutput
Video: Kodi, Harmony HUB, Chromecast
Sensors: You name it I got 1.
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 »

Search the differences ;)

Code: Select all

<?php
$items=array('Bijkeuken','Garageportaal');
foreach ($items as $item)
    if ($d['$item']['s']=='On'
    && past('$item')>60) {
    sw('$item', 'Off');
    lg('_cron60test');
}
?>

Code: Select all

<?php
$items=array('Bijkeuken','Garageportaal');
foreach ($items as $item)
    if ($d[$item]['s']=='On'
    && past($item)>60) {
    sw($item, 'Off');
    lg('_cron60test');
}
?>
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 »

But, keep in mind that this will switch off always after 60 seconds.
You should do something like this, I wouldn't use a array for that:

Code: Select all

<?php
if ($d['Bijkeuken']['s]=='On'&&$d['PIRbijkeuken']['s']=='Off'&&past('PIRbijkeuken')>60) {
	sw('bijkeuken', 'Off');
}
if ($d['Garageportaal']['s]=='On'&&$d['PIRgarageportaal']['s']=='Off'&&past('PIRgarageportaal')>60) {
	sw('Garageportaal', 'Off');
}
?>
With this the light will only switch off 60 seconds after the last movement.
User avatar
sincze
Posts: 1300
Joined: Monday 02 June 2014 22:46
Target OS: Raspberry Pi / ODroid
Domoticz version: 2024.4
Location: Netherlands / Breda Area
Contact:

Re: Pass2PHP

Post by sincze »

Found it [$item] VS ['$item'] :D

@trigun $item is already containing the string (device name) and can be used directly.

@egregius
($d['Bijkeuken']['s]=='On'&&$d['PIRbijkeuken']['s']=='Off'&&past('PIRbijkeuken')>60)

Should be :o

($d['Bijkeuken']['s']=='On'&&$d['PIRbijkeuken']['s']=='Off'&&past('PIRbijkeuken')>60)
Pass2php
LAN: RFLink, P1, OTGW, MySensors
USB: RFXCom, ZWave, Sonoff 3
MQTT: ZIgbee2MQTT,
ZWAVE: Zwave-JS-UI
WIFI: Mi-light, Tasmota, Xiaomi Shelly
Solar: Omnik, PVOutput
Video: Kodi, Harmony HUB, Chromecast
Sensors: You name it I got 1.
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 08 May 2019 14:17 Search the differences ;)
whahaha so this means I was close :) :roll:
I should have looked better at the example :) :oops:
It actually took me quite long to figure out the difference :lol:

haha thnx guys!
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 »

sincze wrote: Wednesday 08 May 2019 14:24 @egregius
($d['Bijkeuken']['s]=='On'&&$d['PIRbijkeuken']['s']=='Off'&&past('PIRbijkeuken')>60)

Should be :o

($d['Bijkeuken']['s']=='On'&&$d['PIRbijkeuken']['s']=='Off'&&past('PIRbijkeuken')>60)
hehe, you have a great eye sincze :)
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 08 May 2019 14:19 But, keep in mind that this will switch off always after 60 seconds.
You should do something like this, I wouldn't use a array for that:

Code: Select all

<?php
if ($d['Bijkeuken']['s]=='On'&&$d['PIRbijkeuken']['s']=='Off'&&past('PIRbijkeuken')>60) {
	sw('bijkeuken', 'Off');
}
if ($d['Garageportaal']['s]=='On'&&$d['PIRgarageportaal']['s']=='Off'&&past('PIRgarageportaal')>60) {
	sw('Garageportaal', 'Off');
}
?>
With this the light will only switch off 60 seconds after the last movement.
you are right, that what I am looking for.
but also when lamp 1 goes on and 30 seconds later lamp 2 goes, they go out at the same time.
i gues your way solves this as well?

Is there a text writer that highlight php rules to good or bad? in case I forget a ' ?
and does php work with Tabs or with spaces (sometimes I count 4 spaces).
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 use BBEdit on Mac.
Notepad++ is pretty good on Windows.

PHP doesn't care what u use, or if you indent, or not. According to phpcs it should be 4 spaces. BBEdit does that automatically ;)
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 »

Trigun wrote: Wednesday 08 May 2019 14:37 but also when lamp 1 goes on and 30 seconds later lamp 2 goes, they go out at the same time.
Everything can be done ;)
You just have to imagine it, and find the skills to do it.
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:
Trigun[/quote wrote: Working on the skillsImage


Sent from my iPhone using Tapatalk
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 08 May 2019 16:02 I use BBEdit on Mac.
Notepad++ is pretty good on Windows.

PHP doesn't care what u use, or if you indent, or not. According to phpcs it should be 4 spaces. BBEdit does that automatically ;)
ah great, will look into it, thank you!
User avatar
sincze
Posts: 1300
Joined: Monday 02 June 2014 22:46
Target OS: Raspberry Pi / ODroid
Domoticz version: 2024.4
Location: Netherlands / Breda Area
Contact:

Re: Pass2PHP

Post by sincze »

Microsoft Visual Studio is also free.
Has a php plugin as well.

Comes in handy if you also have some c++ Arduino Mysensors projects on the side :)
Pass2php
LAN: RFLink, P1, OTGW, MySensors
USB: RFXCom, ZWave, Sonoff 3
MQTT: ZIgbee2MQTT,
ZWAVE: Zwave-JS-UI
WIFI: Mi-light, Tasmota, Xiaomi Shelly
Solar: Omnik, PVOutput
Video: Kodi, Harmony HUB, Chromecast
Sensors: You name it I got 1.
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 »

He Guys,

sorry to bother you with another noob question.
in the examples I see a lot of different statusses but I was wondering what the follwing means:
$d = I assume (device)
's'' = ? set perhaps?
'm' = ?
sw = switch

or maybe you can help where I can find this info, so I don't have to bother you guys :)

thanks guys!

another step closer :)
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'm terrible in writing complete manuals.

$d is the array holding all the information of the system.
So $d['device']['s'] is the status.
t is the timestamp of update.
m is set with the storemode function.
storemode('device', 0); for example.
I use that for dimmers, rollers etc.
0 is mostly automatically, 1 manual. Whatever you want.
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest