HomeGenie Forum

Automation Program Plugins and Wizard Scripting => Help => Topic started by: flybob on August 15, 2014, 08:42:18 AM

Title: Script to trigger Tellstick
Post by: flybob on August 15, 2014, 08:42:18 AM
Hi,
I have a Tellstick (433Mhz TX, similar to X10) in a raspberry USB port.
I can control it using command line tools.

Now i want to control it from HG aswell, but since system calls / scripts is not something HG supports do you have any ideas how it could be done?

I'm thinking of using serial port to the USB port if i can figure out the Tellstick protocol, but if there is a way of using the already existing tools that would be so much easier!
Title: Re: Script to trigger Tellstick
Post by: flossy on September 10, 2014, 08:48:01 PM
Im working on an interface for tellstick. I got switches, dimmers and temp/humidity sensors up and running and hopefully it will be ready for testing in a few days if you're interested.
Title: Re: Script to trigger Tellstick
Post by: flybob on September 11, 2014, 07:57:47 PM
Please do share! I would love to contribute aswell if you need any assistance. I was just about to get down and dirty with it so you wrote this message just in time  :D
Title: Re: Script to trigger Tellstick
Post by: swaner on January 02, 2015, 04:39:00 PM
+1. I would really appreciate if you share this code and I would also be happy to contribute. Even thought the code is not tested yet.

Btw, since this is my first post I would like to say thanks to Genie for making this great product opensource!
Title: Re: Script to trigger Tellstick
Post by: swaner on January 08, 2015, 09:07:35 AM
So I did some development myself and got the basic functionalty to work by adding a new MigInterface :). The problem is to get this to work in Raspberry. I am using a third party dll which is written in c++ and from c# I am using [DllImport] in order to make this to work. This third party dll is opensource and written for both windows, linux and mac: https://github.com/telldus/telldus/tree/master/telldus-core.

Since I have never used Mono before I am confused, can I use the same dll or should I use the linux version? And how does Mono know what binary to use? The naming is different.

Please help, I am lost in the Mono world! :o
Title: Re: Script to trigger Tellstick
Post by: Gene on January 09, 2015, 12:26:59 AM
hi swaner,

telldus library compiled for Windows is binary incompatible with Linux (it is c++, not based on .Net). When compiling the telldus library for Linux, you will get a file with .so extension.
When running HG in Linux, mono will look for the .so library files to search for methods imported with DllImport. So all you have to do is copying both .dll and .so files in the HG folder so it will run on Windows and Linux as well.

g.
Title: Re: Script to trigger Tellstick
Post by: flybob on January 09, 2015, 03:54:49 PM
I have the code from flossy working over here, it requires a new compilation of MIG.dll and uses tellduscore libs.

I'm no fan of C# so I'm happy to get it working at all, and to help you out I can provide you with a copy of the code flossy made. Could be useful to look at perhaps?
Here is his code:
https://github.com/florpan/HomeGenie

I would really love this to become a part of HG in the future, right now i recompile the MIG.dll after every update... since i don't have the time or the knowledge to finish the work.

From a PM send by flossy:
Quote
ok, needed to set up a proper fork and restructure it a bit, but it should be available here https://github.com/florpan/HomeGenie
I'ts public so you should be able to clone it, otherwise send me you github name and ill make sure you have access.

There are two parts, one lib for handling all calls (TelldusLib in Mig/Support libraries). and one MigInterface that adds tellstick as an interface in HG (Mig / Interfaces / Homeautomation / Tellstick.cs).

The lib is mostly a ripoff of the tellstick addon used for switchking, but the plan is a rewrite of that to remove some oddities in the lib.
It depends on the tellstick tools to be installed (tdtool etc for linux). I havent tested it on windows, but it should work there aswell since the pinvoke's for windows is included in the lib aswell.

Compile and dump the new Mig.dll and TelldusLib.dll in the homegeniefolder.
Also since there is no gui to turn it on, you'll need to do that manually by adding

      <Interface Domain="HomeAutomation.Tellstick" IsEnabled="true">
        <Options>
          <Option Name="Port" Value="" />
        </Options>
      </Interface>

to the <MIGService> part of the systemconfig.xml file.

I think thats all =) there are some weird stuff though. The sensors seem to pop up randomly, or my neighbours have a bunch of temperature sensors. That list need to be filtered somehow, i was thinking something simple like a comma separated textfield in the config where you can add the sensors you want to be available and then ignore the rest. Keep it running for a while and you'll see the liste of devices increasing in size.
Title: Re: Script to trigger Tellstick
Post by: swaner on January 20, 2015, 04:07:59 PM
Thanks guys! Got it working now be adding the .so files  ;D.
I have also added the gui needed for activating the telldus interface.

I agree that it would be nice to have this included into HomeGenie, but since it depends on the tellstick tools be be installed first it's not really a perfect solution. Guess it's up to the project owners?
Title: Re: Script to trigger Tellstick
Post by: flybob on January 21, 2015, 07:48:35 PM
Nicely done!
Great to have a GUI for the interface aswell.
I don't know of any other way than using the telldus core to get it working, perhaps that could be a prerequisite before being able to activate the interface in Homegenie, leaving it up to the user to install (with a minor help perhaps)

What do you think Gene?

Swaner: Can you please share your work so we can enjoy the fruits? =)
Title: Re: Script to trigger Tellstick
Post by: swaner on February 10, 2015, 02:59:50 PM
Sorry for the very late reply. I would be happy to share the code. Modified flossys code slightly in order to simulate two way communication (pressing a remote control button triggers homegenie on/off).

I will try to make a forge this evening. It would be great if I could include just the MIGInterface and the Support Library to the main repo. Didn't realize how often this project get's updated, which off-course is a great thing ;)!
Title: Re: Script to trigger Tellstick
Post by: swaner on February 10, 2015, 06:57:30 PM
Please try to download, compile and run from https://github.com/swaner/HomeGenie. Let me know if you have any issues or bugs.
Title: Re: Script to trigger Tellstick
Post by: Varazir on February 20, 2015, 02:21:19 PM
Hello,

If I use the image for RaspberryPI I don't get this?
If not, how can implement it ? 

TIA
Daniel
Title: Re: Script to trigger Tellstick
Post by: swaner on February 23, 2015, 08:31:28 AM
Hi Daniel

You have to download the sourcecode and compile the project in Visual Studio 2013 and manually move the files to the Pi. Search the forum for how to do this.

Also, the telldus-core lib needs to be installed on the raspberry pi. I followed this guide (in Swedish, but I guess most tellstick users are Scandinavian?): https://blogg.itslav.nu/?p=875. Step 4-6 are the only steps required for telldus-core lib.
Title: Re: Script to trigger Tellstick
Post by: Varazir on February 23, 2015, 09:27:11 AM
Hi Daniel

You have to download the sourcecode and compile the project in Visual Studio 2013 and manually move the files to the Pi. Search the forum for how to do this.

Also, the telldus-core lib needs to be installed on the raspberry pi. I followed this guide (in Swedish, but I guess most tellstick users are Scandinavian?): https://blogg.itslav.nu/?p=875. Step 4-6 are the only steps required for telldus-core lib.

Thanks, I'll take a look at it.


KR
Daniel


Title: Re: Script to trigger Tellstick
Post by: flybob on February 27, 2015, 12:40:19 PM
swaner:

Is it ready to be introduced to the master branch? How about a pull request to gene?
Would be better instead of us having a fork for tellstick support only.


edit:
Saw that you tried that just a few days ago and got a comment from gene 2 hours ago... so you are really close now, great!
Title: Re: Script to trigger Tellstick
Post by: swaner on April 18, 2015, 04:27:52 PM
Small update here, HomeGenie has now support for loadable interface drivers so I modified my fork to a new repo:
https://github.com/swaner/HomeGenieTelldusInterface.

I had some problems unpacking the zip-files but maybe you are more lucky?::) Anyway, I got it to work by copying the zipped files manually instead.
Title: Re: Script to trigger Tellstick
Post by: sintei on June 17, 2015, 04:43:55 PM
How do you install this on a windows machine?
Cheers
Title: Re: Script to trigger Tellstick
Post by: swaner on June 17, 2015, 05:17:41 PM
You need to install TelldusCenter which can be found at http://www.telldus.se/products/nativesoftware. (http://www.telldus.se/products/nativesoftware.)
Then add your devices in Telldus Center.

Finally you can install Telldus interface driver in HomeGenie:
1. Download the zip file located here: https://github.com/swaner/HomeGenieTelldusInterface/raw/master/Tellstick_0_9.zip. (https://github.com/swaner/HomeGenieTelldusInterface/raw/master/Tellstick_0_9.zip.)
2. Open HomeGenie and goto Configure->Interfaces.
3. Press Import Interface Driver and locate the file downloaded in step 1
Title: Re: Script to trigger Tellstick
Post by: sintei on June 18, 2015, 07:31:35 AM
Thanks Swaner,

I thought I did precisely this yesterday and nothing happened.
Will revisit this when I get home from work.
Probably just some fault behind my keyboard ;)
Cheers!
Title: Re: Script to trigger Tellstick
Post by: swaner on June 18, 2015, 10:59:50 AM
I thought I did precisely this yesterday and nothing happened.


Yes, I see the problem now. There seems to be a problem reading the zip-package in HomeGenie.
When debugging I get this this error on line 435 in Utility.cs: An item with the same key has already been added.
Stacktrace:
Code: [Select]
at System.Collections.Generic.Dictionary`2.Insert(TKey key, TValue value, Boolean add)
   at System.IO.Packaging.ZipPackage.ContentTypeHelper.ProcessDefaultTagAttributes(XmlTextReader reader)
   at System.IO.Packaging.ZipPackage.ContentTypeHelper.ParseContentTypesFile(ZipFileInfoCollection zipFiles)
   at System.IO.Packaging.ZipPackage.ContentTypeHelper..ctor(ZipArchive zipArchive, IgnoredItemHelper ignoredItemHelper)
   at System.IO.Packaging.ZipPackage..ctor(String path, FileMode mode, FileAccess access, FileShare share, Boolean streaming)
   at System.IO.Packaging.Package.Open(String path, FileMode packageMode, FileAccess packageAccess, FileShare packageShare, Boolean streaming)
   at System.IO.Packaging.Package.Open(String path, FileMode packageMode, FileAccess packageAccess)
   at HomeGenie.Service.Utility.UncompressZip(String archiveName, String destinationFolder) in c:\dev\HomeGenie\HomeGenie\Service\Utility.cs:line 435

The exception is thrown inside ZipPackage.cs: http://referencesource.microsoft.com/#WindowsBase/Base/System/IO/Packaging/ZipPackage.cs,1323 (http://referencesource.microsoft.com/#WindowsBase/Base/System/IO/Packaging/ZipPackage.cs,1323) .

Maybe someone more experienced in HomeGenie can have a look?

Not sure if this is a bug in HomeGenie or something wrong with the zip-package. You can try to unzip and zip again on your machine (I used 7-zip so maybe try another software?). Otherwise the files can be copied manually.

EDIT: Tried the other packages (WeecoBoard and MqttBroker) and got the exact same error, so there seems to be a generic error: https://github.com/genielabs/HomeGenie/blob/master/BaseFiles/Common/ADDONS.md (https://github.com/genielabs/HomeGenie/blob/master/BaseFiles/Common/ADDONS.md)
Title: Re: Script to trigger Tellstick
Post by: swaner on June 18, 2015, 11:59:15 AM
Update, I managed to get this to work by using another zip-utility. What do you think about using this tool instead Gene?

Replacement of existing method on line 431 inside HomeGenie\Service\Utility:
Code: [Select]
internal static List<string> UncompressZip(string archiveName, string destinationFolder)
        {
            List<string> extractedFiles = new List<string>();

            // Unarchive (unzip)
            System.IO.Compression.ZipFile.ExtractToDirectory(archiveName, destinationFolder);
            extractedFiles.AddRange(Directory.GetFiles(destinationFolder));

            return extractedFiles;
        }

In order to use this a reference to assembly System.IO.Compression.FileSystem (included in the .net framework) is needed.
Title: Re: Script to trigger Tellstick
Post by: Gene on June 18, 2015, 01:24:52 PM
Hello guys,

I think the problem is related to a bug in the runtime.
A work-around is to modify ContentTypes.xml file in the ZIP archive:

Code: [Select]
<?xml version="1.0" encoding="utf-8"?>
<Types xmlns="http://schemas.openxmlformats.org/package/2006/content-types">
    <Default Extension="so" ContentType="" />
    <Default Extension="dll" ContentType="" />
    <Default Extension="xml" ContentType="" />
    <Default Extension="TXT" ContentType="" />
    <Default Extension="txt" ContentType="" />  <<<------ remove this
    <Default Extension="html" ContentType="" />
    <Default Extension="png" ContentType="" />
    <Default Extension="mdb" ContentType="" />
</Types>
remove the entry:
Code: [Select]
<Default Extension="txt" ContentType="" />
and replace the xml file in the archive.

Cheers,
g.
Title: Re: Script to trigger Tellstick
Post by: swaner on June 18, 2015, 01:46:24 PM
Great finding! Now it works :). Noticed that the other add-ons also has the same file (MqttBroker and WeecoBoard).

sintei: I have updated the zip-file on github. So please try again https://github.com/swaner/HomeGenieTelldusInterface/raw/master/Tellstick_0_9.zip
Title: Re: Script to trigger Tellstick
Post by: sintei on June 18, 2015, 08:40:14 PM
The plugin loaded fine.
But then restarted HG over and over again.
I could see the problem was when a Temperature/Hydrometer was sending signals.
It triggered a status install thingie and restarted HG.
Every time it was sensed HG restarted.
Sensors can't be erased, only "non visible" in telldus because they send data all the time.

Also, I am having other problems: Dimmer will let me turn on or dim, but only once.
It will not let me turn off. Or dim another percentage.
If I turn off the light manually I can see that I can start the light from HG again, so this is weird.

And another "switch" works OK. Only thing not working is the "toggle"-button in the widget, which really is just cosmetics for me as I will not use it.