PHP interface for TellStick, HomeAutomation v2.0.2 released!

Moderator: Telldus

Pal
Posts: 25
Joined: Fri Mar 17, 2023 9:45 am

Re: PHP interface for TellStick, HomeAutomation v1.2.2 relea

Post by Pal »

I've now made a finger friendly PoC with night.css as template. You can log in as demo / d3m0 and have a look at https://www.home.pal.pp.se/auto/pal.mobile.php

I just made a few changes in mobile.php, devices.php and mobile/night.css. Some of the devices are fake devices, but as I said it's a PoC. The code is kind of ugly at the moment, so I want to tidy things up before I'll let you see the PHP source. :) And I guess I could make prettier button images. And the title attributes don't do much on touch screens...

Anyway, I've tried it on Galaxy Tab and Nokia N900, and both look fine and are easy to finger on. I don't have an iPhone, so if someone has one, please load the page and give me a screen dump.

I'm working on the Crestron interface. It wants (unprintable) hex code commands over TCP, so if someone's got a good PHP telnet module that can send raw hex codes, please let me know. Then I don't have to do sockets and code everything from scratch.

MVH
/P
tom_rosenback
Posts: 779
Joined: Fri Mar 17, 2023 9:45 am
Contact:

Re: PHP interface for TellStick, HomeAutomation v1.2.2 relea

Post by tom_rosenback »

Pal wrote:I've now made a finger friendly PoC with night.css as template. You can log in as demo / d3m0 and have a look at https://www.home.pal.pp.se/auto/pal.mobile.php

I just made a few changes in mobile.php, devices.php and mobile/night.css. Some of the devices are fake devices, but as I said it's a PoC. The code is kind of ugly at the moment, so I want to tidy things up before I'll let you see the PHP source. :) And I guess I could make prettier button images. And the title attributes don't do much on touch screens...

Anyway, I've tried it on Galaxy Tab and Nokia N900, and both look fine and are easy to finger on. I don't have an iPhone, so if someone has one, please load the page and give me a screen dump.

I'm working on the Crestron interface.
It wants (unprin
table) hex code commands over TCP, so if someone's got a good PHP telnet module that can send raw hex codes, please let me know. Then I don't have to do sockets and code everything from scratch.

MVH
/P
Hi P,

Looks good so far on my Nokia E72.

One thing I'm missing is the possibility to push on/off directly, not only toggling. I don't know if it is a must to have the possibility to do so but I feel like when a device is not responding I prefer to push on several times instead of toggling... What do you think?

We have got a new feature coming. In short it is an option to allow the user to keep the current status of a device (for a configurable time) and in this way overriding the schedules. We had thought of an additional icon for every device, I don't know how this will fit in into your design, but you could keep this in your mind. Send me an email if you need any further details on this new feature.

Thank you!
//Tom

Senaste info och release om/av HomeAutomation hittas här http://karpero.mine.nu/ha
Latest info and release of HomeAutomation can be found here http://karpero.mine.nu/ha
Pal
Posts: 25
Joined: Fri Mar 17, 2023 9:45 am

Re: PHP interface for TellStick, HomeAutomation v1.2.2 relea

Post by Pal »

tom_rosenback wrote:One thing I'm missing is the possibility to push on/off directly, not only toggling. I don't know if it is a must to have the possibility to do so but I feel like when a device is not responding I prefer to push on several times instead of toggling... What do you think?
It's very easy to have two different mobile pages - one with toggle icons, and one with on/off icons, and then choose which one you want depending on the size of your device. You could make a $_GET variable to change between the two layouts.
tom_rosenback wrote:We have got a new feature coming. In short it is an option to allow the user to keep the current status of a device (for a configurable time) and in this way overriding the schedules. We had thought of an additional icon for every device, I don't know how this will fit in into your design, but you could keep this in your mind. Send me an email if you need any further details on this new feature.
The main thing with my design are the finger friendly buttons. How many buttons, and how they're aligned, all depends on the size of your device. As long as it fits your screen, you can have as many buttons as you like, and put them in the desired number of columns.

You have done a very nice job letting the user place icons on the house plan. You could make the same kind of interface where users can put buttons on a screen layout (using divs in stead of a table, and maybe with a snap-in grid), and then leave it up to the user (with a reasonable default mobile.php to begin with).

/P

BTW: The mobile/night.css body have background #84bdf3 - I guess it should be #000000.
Pal
Posts: 25
Joined: Fri Mar 17, 2023 9:45 am

Re: PHP interface for TellStick, HomeAutomation v1.2.2 relea

Post by Pal »

tom_rosenback wrote:One thing I'm missing is the possibility to push on/off directly, not only toggling.
I made this in ten minutes: https://www.home.pal.pp.se/auto/pal.mobile_2.php

Since I'm not using the status icons, the nice animated wait icon doesn't appear, but I guess it won't be that hard to put it back in.
Pal
Posts: 25
Joined: Fri Mar 17, 2023 9:45 am

Re: PHP interface for TellStick, HomeAutomation v1.2.2 relea

Post by Pal »

tom_rosenback
Posts: 779
Joined: Fri Mar 17, 2023 9:45 am
Contact:

Re: PHP interface for TellStick, HomeAutomation v1.2.2 relea

Post by tom_rosenback »

Pal wrote:
tom_rosenback wrote:One thing I'm missing is the possibility to push on/off directly, not only toggling. I don't know if it is a must to have the possibility to do so but I feel like when a device is not responding I prefer to push on several times instead of toggling... What do you think?
It's very easy to have two different mobile pages - one with toggle icons, and one with on/off icons, and then choose which one you want depending on the size of your device. You could make a $_GET variable to change between the two layouts.
tom_rosenback wrote:We have got a new feature coming. In short it is an option to allow the user to keep the current status of a device (for a configurable time) and in this way overriding the schedules. We had thought of an additional icon for every device, I don't know how this will fit in into your design, but you could keep this in your mind. Send me an email if you need any further details on this new feature.
The main thing with my design are the finger friendly buttons. How many buttons, and how they're aligned, all depends on the size of your device. As long as it fits your screen, you can have as many buttons as you like, and put them in the desired number of columns.

You have done a very nice job letting the user place icons on the house plan. You could make the same kind of interface where users can put buttons on a screen layout (using divs in stead of a table, and maybe with a snap-in grid), and then leave it up to the user (with a reasonable default mobile.php to begin with).

/P

BTW: The mobile/night.css body have background #84bdf3 - I guess it should be #000000.
I have now checked all your examples, all of them are working solutions. Depending on what the user wan´t Toggle/on/off could be shown and as you said if it could be made configurable for the mobilepage. Feel free to send me the "cleaned" source when you are done.
//Tom

Senaste info och release om/av HomeAutomation hittas här http://karpero.mine.nu/ha
Latest info and release of HomeAutomation can be found here http://karpero.mine.nu/ha
Pal
Posts: 25
Joined: Fri Mar 17, 2023 9:45 am

Re: PHP interface for TellStick, HomeAutomation v1.2.2 relea

Post by Pal »

I made the code a bit more pleasant to the eye, but you could make it even prettier. Creating the buttons should be done with functions (their content as parameters), and so on. Anyway, it's pretty enough to let people see it. :)

I've attached the files, and I prefixed all my variables, classes and other things with "pal", so you can easily find any changes.

I added a new section with these four entries to the settings database table and the language file (you can't see it when logged in as demo):

Code: Select all

Mobile page 
Show toggle column:	Yes No
Show off column:	Yes No
Show on column:	Yes No
Show all on/off buttons:	Yes No
I added this to mobile.php:

Code: Select all

foreach (array('palToggle', 'palOn', 'palOff', 'palAll') as $palType) {
	if (isset($_GET[$palType])) {
		$palCol[$palType] = ($_GET[$palType] == '0' || $_GET[$palType] == 'false' || $_GET[$palType] == 'off' || $_GET[$palType] == 'no' || $_GET[$palType] <= 0) ? false : true;
	} else {
		$palCol[$palType] = $_SESSION[CFG_SESSION_KEY]["settings"][$palType];
	}
}
And changed the call to generateMobileDeviceList to:

Code: Select all

$page .= generateMobileDeviceList($display, $dispSub, $palCol['palToggle'], $palCol['palOn'], $palCol['palOff'], $palCol['palAll']);
It would've been enough just to use the CFG_SESSION_KEY stuff directly in the function call, but I made the $_GET stuff before turning it into real settings. And anyway, it might be a good thing to be able to override the settings using the URL.

Then I rewrote the mobile.php to the attached version, and added a bunch of classes to the CSS file (also attached).

I copied the devices.php file and included the new pal.devices.php file in the new pal.mobile.php file, so I have no idea what other pages I destroyed with my changes to generateMobileDeviceList.

/P
Attachments
devices-night.zip
(2.78 KiB) Downloaded 820 times
Pal
Posts: 25
Joined: Fri Mar 17, 2023 9:45 am

Re: PHP interface for TellStick, HomeAutomation v1.2.2 relea

Post by Pal »

Sorry, forgot: The URL is https://auto.home.pal.pp.se/auto/pal.mobile.php and log in as demo/d3m0.

You can customize what to see using this URL: https://auto.home.pal.pp.se/auto/pal.mo ... 1&palAll=1
Pal
Posts: 25
Joined: Fri Mar 17, 2023 9:45 am

Re: PHP interface for TellStick, HomeAutomation v1.2.2 relea

Post by Pal »

Inspired by yesterday, I also made a Crestron PoC tonight. So far, the code creates a Crestron object that can:

*) Be configured with:
var $server;
var $ip;
var $port;
var $terminator;
var $password;
var $socket = NULL;
var $showErrors = false;
var $debug = false;
*) Resolve server names to IP addresses.
*) Connect to the Crestron CPU over TCP.
*) Retrieve all dimmer/relay/scenario settings as an array of key/value pairs (and the key codes are unique for each setup, so some kind of local translation table is needed for each installation, but you already do the same thing with the Tellstick numerical codes).
*) Send a command.
*) Retrieve the output of the command (in the same key/value pairs format).

The terminator is the hexadecimal value that terminates commands sent, and each key/value pair received. In my setup it is 0x03 and I think it's the default. There are no newlines ever sent or received. There's no user login, just a password. The i=1 output only shows key with values other than 0 (so it won't list any lights turned off or dimmers at minimum). There's a keep alive command (h=0h) but a better solution is to use periodical "i=1" (to keep track of on/off, dimmer levels and active scenarios). There's no need for any sleeps to wait for stuff (at least not in my setup over 1 Gbit/s LAN), but I don't know if it is buffering or just fast.

I've so far succeeded in getting the current status (i=1), setting the dimmer level (0-65535) for a dimmer of my choice, turning on/off a relay of my choice and choosing a scenario of my choice.

Left to do:

Save scenarios. The TCP interface mimics the wall buttons (and the XPanel interface), which means that you save stuff by keeping buttons pressed for a few seconds. You do that the TCP way by sending a "button down" command, followed by a "button up" command after the specified amount of time. As long as no network connection fuss or similar is in the way, it should be easy enough to do with a simple timer.

Integrate Crestron scenarios into Home Automation scenarios. I haven't tried Home Automation scenarios yet, so I have no ideas on how to make it nice.

General integration into Home Automation. So far, this is standalone code. The object is there, but there's no integration with any of your code. I choose device and what to do by simply assigning variables directly in the code. The Crestron relays/dimmers should exist as devices in the database, as any other device.

User interface. This is what I've got so far: https://auto.home.pal.pp.se/auto/pal.crestrontest.php (output from i=1 at the moment) which is... less than useful without access to the code, and not much even with access. :) I guess much can be recycled from existing Home Automation code.

Initiation process. Since it won't list keys with 0 value, we need to find a way to make it do so, or ask the user to turn everything on and then click the query button to read and store all the channels.

Settings stuff in database and on settings page (which, when put in the database, is automatic)

/P

Edit: I unintentionally made it somewhat stateful. Since I don't unset the array variable keeping the output, and I use the key/value pairs as keys/values in the array, it keeps the last known state of all equipment for as long as the object exists (which is the same as the session lifetime I guess). And if anything starting at 0 (and thus unknown) is turned on, it will be added to the array at the next i=1. If the PHP object is used to turn it on, it is added instantly.
Pal
Posts: 25
Joined: Fri Mar 17, 2023 9:45 am

Re: PHP interface for TellStick, HomeAutomation v1.2.2 relea

Post by Pal »

Pal wrote:General integration into Home Automation. So far, this is standalone code. The object is there, but there's no integration with any of your code. I choose device and what to do by simply assigning variables directly in the code. The Crestron relays/dimmers should exist as devices in the database, as any other device.
Done. Now a bunch of my Crestron stuff is added into the database as device types crestrondimmer and crestronrelay, and I've edited functions.php and houseplan.php to support the two new types. It's working fine: https://auto.home.pal.pp.se/auto/?display=houseplan

Left to do:

As usual, the code is ugly, with edited tdtool functions and misleading variable/function names. I'll separate the Crestron/TDTool logics from eachother before I'm satisfied.

There's a funny bug that I can't understand. One (only one: the bath room mirror) of the Crestron relays changes icon after some time (30 seconds or so), and becomes a TV box(!). I fail to see any differences between that relay and the other relays (that behaves fine). At the same time, some of the icon changes status, and some of the drop downs changes percentage.

The icons aren't working that well. They sometimes are lit and sometimes not, seemingly without any association to reality. But I guess we want to query the i=1 command for the status (and the dim level) for all Crestron devices anyway (no such code is there yet).

The object is recreated on every action. It should use an existing object if there is one, and only create one when needed.

/P
Pal
Posts: 25
Joined: Fri Mar 17, 2023 9:45 am

Re: PHP interface for TellStick, HomeAutomation v1.2.2 relea

Post by Pal »

Update: I am now coding for HA 2.0, and the Crestron stuff is capable of all normal operations regarding turning on/off and setting dim levels. Also, the code is clean and all Telldus functions has gotten Crestron cousins (event those I don't use yet). And I added configuration options and (English) translations for the new stuff. All this also means that I don't have to build any new user interfaces, since the integration makes the existing HA GUI modules handle all the Crestron operations automagically.

Left to do:

1. The "Update from Crestron" (cousin to "Update from Tellstick" on the settings page) read the i=1 string, converts it to an array of key/value pairs and puts everything in the database as it is supposed to. However, the i=1 string contains more than dimmers and relays. It also contains analogue data entries showing fade times and delay times. And it contains digital entries showing things like presets statuses, buttons statuses, fading/delaying timers statuses and such. Since analogue data is represented by keys beginning with a no matter if it is a dimmer or a fade/delay time setting, I haven't found any way to distinguish between them. And the same goes for the digital stuff. For instance, when the i=1 returns "d164=1", there's no way to tell if this is a relay, a preset or some other digital data. The result is that the database gets clogged with devices that are not devices. I have emailed my supplier about this, so we'll see what they say. The workaround is to show the user a page where he can sort out which is what (it would still be nicer than to enter it manually into the database).

2. Get the status from the dimmers and relays. To turn on or off a relay, you always send "dXX=1" (i.e. "press the button"), no matter if it's on or off. The reply from Crestron is "dXX=X" where the last X is 1 or 0, depending on the status (after the button press). I need to read the value and put it in the database. Not a hard thing to do, but I haven't done it yet. Also, when the autorefresh is done (for the Tellstick devices) the same thing should be done for the Crestron stuff, i.e. send an i=1 and put the resulting statuses into the database (this time we know what ID's to read from). This could also be done every time we create the Crestron object (since the reply when logging in is an i=1 output).

3. Keep the Crestron object alive. I tried to do that, but apparently I failed, because it is till recreated at every operation.

4. Scenarios.

The mobile page has also been integrated into version 2.0, and it is working as expected. It is now integrated into the existing files, and not put into its own file.

I also fixed some ordinary bugs along the way (including the icon bugs mentioned). You'll get those in email.

Regards
/P
tom_rosenback
Posts: 779
Joined: Fri Mar 17, 2023 9:45 am
Contact:

Re: PHP interface for TellStick, HomeAutomation v1.2.2 relea

Post by tom_rosenback »

We are now working hard to get v2.0 ready and out for testing. There is a few things still to fix/test but in the whole it starts to be ready.

I created a new sub-project, Weather parser. This parser supports at the moment the wview format but can easily be expanded for other formats aswell. The parser reads a text file and inserts the selected data into the database. The parser should be set up as a cron-job which is run with a certain interval, for example every 15th minute. After the parsing has been done one should go to Configuration => Temperaturesensors and do a "Update temperaturesensors" which reads the temperaturesensors from the database and inserts them into the Temperaturesensors list. The name can the be change to be more user friendly.

Code: Select all

php parser.php
Simple as that. The parser can also be run from the browser if one puts the files in the www-root.

Weather Parser v0.1 can be downloaded from the HomeAutomation homepage which can be found in my signature.
//Tom

Senaste info och release om/av HomeAutomation hittas här http://karpero.mine.nu/ha
Latest info and release of HomeAutomation can be found here http://karpero.mine.nu/ha
tom_rosenback
Posts: 779
Joined: Fri Mar 17, 2023 9:45 am
Contact:

PHP interface for TellStick, HomeAutomation v2.0 released!

Post by tom_rosenback »

HomeAutomation v2.0 is now released. We have worked hard now for quite some time to get this release out, we have also gotten it properly tested with the help of a few selected testers. I hope most bugs are fixed.

So what has happened in v2.0

The biggest change in 2.0 is the scheduler, it is completely rebuilt with several different types of activations, support for absolute dimlevel, groups, and dynamic activations (eg temp outside more than 20 put light 2 on). Random activations is also something that is new in the new scheduler. As I just mentioned, there is now support for groups which can be used to easily turn on/off a room or an entire floor. Macros are also new, they can in turn be used for example to activate the "Watch TV" lighting, which would that eg light 1 & 2 will turn off, light 3 dimmed to 45% and light 4 on... U name it. Macros are also support to change the chosen scenario, an example for this is "On trip"-macro that would turn off all devices except light 2 and select the away scenario so that the right schedule is active while you are away.

Mobile pages have also been rebuilt, which we hope will be convenient to use with touchscreen devices (phones, pads...).

We have also created a user guide to help users to receive help with everything from installation to use of HomeAutomation. User Guide is included in the zip file, read it if you feel uncertain about how something works, and if we have been unclear insert a question here or via HomeAutomation homepage.

All this plus a whole bunch of other fixes and improvements in 2.0, but in order not to repeat myself you can instead read a more detailed changelog in Mantis, [url] http://karpero.mine.nu/mantis [/ url].

HomeAutomation v2.0 can be downloaded from HomeAutomation homepage which can be found in my signature.

Thanks to all bug testers for comments and reports.
//Tom

Senaste info och release om/av HomeAutomation hittas här http://karpero.mine.nu/ha
Latest info and release of HomeAutomation can be found here http://karpero.mine.nu/ha
tom_rosenback
Posts: 779
Joined: Fri Mar 17, 2023 9:45 am
Contact:

Re: PHP interface for TellStick, HomeAutomation v2.0.1 relea

Post by tom_rosenback »

For those who can´t get scheduler to work in 2.0 there is a bug-fix release now available on HomeAutomation homepage, v2.0.1
//Tom

Senaste info och release om/av HomeAutomation hittas här http://karpero.mine.nu/ha
Latest info and release of HomeAutomation can be found here http://karpero.mine.nu/ha
tom_rosenback
Posts: 779
Joined: Fri Mar 17, 2023 9:45 am
Contact:

PHP interface for TellStick, HomeAutomation v2.0.2 released!

Post by tom_rosenback »

We have now released a bug fix release, v2.0.2. There is not any criticial fixes but still things which are nice to have. The only new thing is that it is now possible to login directly with parameters in the URL (could be used from smartphones and likewise).

Copying from the changelog what has changed.

Code: Select all

- [Houseplan] Houseplan shows icons in wrong place for portrait images
- [New functionality] Add possibility to login with parameters in URL
- [General] Add info to login form when incorrect credentials are given
- [Languages] After name should be Last name in english translation
- [Scheduler] Selecting All devices gives error message
- [Houseplan] Houseplan image is not uploaded
To login directly from URL you can follow the example below

Code: Select all

http://yourhost.com/homeautomation/index.php?dologin=1&login_username=YourUsername&login_password=YourPassword
//Tom

Senaste info och release om/av HomeAutomation hittas här http://karpero.mine.nu/ha
Latest info and release of HomeAutomation can be found here http://karpero.mine.nu/ha
Post Reply