Page 47 of 76

Re: Pass2PHP

Posted: Tuesday 07 May 2019 15:04
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 ;) )

Re: Pass2PHP

Posted: Tuesday 07 May 2019 15:37
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

Re: Pass2PHP

Posted: Tuesday 07 May 2019 16:17
by Egregius
I get different contents with nano /etc/crontab and with crontab -e :?

Re: Pass2PHP

Posted: Tuesday 07 May 2019 16:26
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

Re: Pass2PHP

Posted: Tuesday 07 May 2019 16:42
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.

Re: Pass2PHP

Posted: Wednesday 08 May 2019 13:28
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?

Re: Pass2PHP

Posted: Wednesday 08 May 2019 14:15
by sincze
Not necessary. Check the sw function it can handle arrays already. Use that instead :)

Re: Pass2PHP

Posted: Wednesday 08 May 2019 14:17
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');
}
?>

Re: Pass2PHP

Posted: Wednesday 08 May 2019 14:19
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.

Re: Pass2PHP

Posted: Wednesday 08 May 2019 14:24
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)

Re: Pass2PHP

Posted: Wednesday 08 May 2019 14:31
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!

Re: Pass2PHP

Posted: Wednesday 08 May 2019 14:34
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 :)

Re: Pass2PHP

Posted: Wednesday 08 May 2019 14:37
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).

Re: Pass2PHP

Posted: Wednesday 08 May 2019 16:02
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 ;)

Re: Pass2PHP

Posted: Wednesday 08 May 2019 16:03
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.

Re: Pass2PHP

Posted: Wednesday 08 May 2019 16:04
by Trigun
Egregius wrote:
Trigun[/quote wrote: Working on the skillsImage


Sent from my iPhone using Tapatalk

Re: Pass2PHP

Posted: Wednesday 08 May 2019 16:21
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!

Re: Pass2PHP

Posted: Wednesday 08 May 2019 17:01
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 :)

Re: Pass2PHP

Posted: Wednesday 08 May 2019 20:15
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 :)

Re: Pass2PHP

Posted: Wednesday 08 May 2019 21:07
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.