Author Topic: Coding an Automatic Lighting controller in GSD  (Read 17124 times)

tschak909

  • LinuxMCE God
  • ****
  • Posts: 5549
  • DOES work for LinuxMCE.
    • View Profile
Re: Coding an Automatic Lighting controller in GSD
« Reply #15 on: January 17, 2009, 11:35:07 pm »
Sorry, I did not mean to yell.

Ok,

Prove me wrong.

Do a proof of concept.

-Thom

Zaerc

  • Alumni
  • LinuxMCE God
  • *
  • Posts: 2256
  • Department of Redundancy Department.
    • View Profile
Re: Coding an Automatic Lighting controller in GSD
« Reply #16 on: January 18, 2009, 12:02:55 am »
...
I'm not saying or thinking about rewrite of plugins in Ruby, but am trying to say, that putting too much "smart" behaviour into hardcoded plugins that will actually change with each release being on half or full year schedule is not IMHO a way to go...
...

So far there have been weekly updates for 0810 (alpha).

What if for instance Media plugin will do something that you don't like (for example: in my case Media plugin switches my amplifier off, when screensaver starts on our main hybrid and we loose music - ok, I can untie a pipe etc... Also, try to make speech announcemet while playing playlist it will tear your system apart - at least does to mine...)? Then you will not be able to change that behaviuor with reasonable time or effort.

Those are what we call bugs and need to be fixed properly.  And changes will always take time and effort, what you call reasonable or not isn't very relevant.
"Change is inevitable. Progress is optional."
-- Anonymous


jondecker76

  • Alumni
  • wants to work for LinuxMCE
  • *
  • Posts: 763
    • View Profile
Re: Coding an Automatic Lighting controller in GSD
« Reply #17 on: January 18, 2009, 12:40:58 am »
Also remember that you can respond to events with your own commands without having to code a thing in C++ or GSD at all. In fact, most things should be possible with just these features alone.

For those special situations where you absolutely have to have complete control over things, I did finish implementing an "Unmanaged" room type that will have absolutely no automatically generated scenarios. For 0810, if you want your own behavior you can use this room type, and make your own event responses and scenarios (though you would be surprised at how much you have to manually add in order to get the functionality that LMCE has already provided by generating them for you)

bulek

  • Administrator
  • wants to work for LinuxMCE
  • *****
  • Posts: 909
  • Living with LMCE
    • View Profile
Re: Coding an Automatic Lighting controller in GSD
« Reply #18 on: January 18, 2009, 09:14:40 am »
Hi,

...

I agree,what can be done with simple event handling and timed handling and scenarios over web-admin, it should be. I think we can get idea from enhancements to event handling that MiaCasa or Casaverde (whatever it is) did. We need some easier interface to do it...

What my idea is also talking about is to prepare few Ruby modules/classes that would ease implementation of SW for more complex behaviour/criteria/action things... It would be nice to have easy to understand skeleton in Ruby that would start, connect to DCERouter with possibility to register interceptor, and then ability for easy access to state of devices, acting upon received events, doing some actions (sending commands,new events, read data, etc...). Something similar DDamron did with PLCBus driver...

Also we should disect existing set of "prepackaged" special events and contribute missing parts that would ease handling...

I also think that Unmanaged room is a good idea, but maybe easier dealing with autogenerated scenarios (one click to disable certain scenarios - they can stay there, just being disabled) is a better answer... But in the mean time , Unmanaged room is also a good option...

Regards,

Bulek.


Thanks in advance,

regards,

Bulek.

Zaerc

  • Alumni
  • LinuxMCE God
  • *
  • Posts: 2256
  • Department of Redundancy Department.
    • View Profile
Re: Coding an Automatic Lighting controller in GSD
« Reply #19 on: January 18, 2009, 12:23:50 pm »
...
Also we should disect existing set of "prepackaged" special events and contribute missing parts that would ease handling...
...

Good idea, keep us posted on your progress.
"Change is inevitable. Progress is optional."
-- Anonymous


chrisbirkinshaw

  • Guru
  • ****
  • Posts: 431
    • View Profile
Re: Coding an Automatic Lighting controller in GSD
« Reply #20 on: January 18, 2009, 07:28:17 pm »
Thom is right, of course, that we have the respond to events in the web admin and we should just extend that.

My problem is however that I have no C programming skills so I am unable to help directly.

I had hoped that I could create some "duct tape" which would help a few people out getting automatic motion-triggered lighting working in the mean-time. Eventually as the respond to events in improved this would no longer be necessary. At the moment I have misterhouse, interfaced over sockets to the DCE router, which is quite untitdy as I have to map X10 codes to device ids in there too.

I'm basically just looking for advice to help me create this duct-tape. I am also happy to make suggestions for improvements to the Lighting Plugin and help out with testing, Wiki writing etc. It's not one or the other.

Regards,

Chris



chrisbirkinshaw

  • Guru
  • ****
  • Posts: 431
    • View Profile
Re: Coding an Automatic Lighting controller in GSD
« Reply #21 on: January 18, 2009, 07:29:06 pm »
BTW if the Respond to Events was enhanced this would be way better than Misterhouse anyway. Nobody wants to write code as a configuration step!

Chris

bulek

  • Administrator
  • wants to work for LinuxMCE
  • *****
  • Posts: 909
  • Living with LMCE
    • View Profile
Re: Coding an Automatic Lighting controller in GSD
« Reply #22 on: January 19, 2009, 02:56:44 am »
Thom is right, of course, that we have the respond to events in the web admin and we should just extend that.

My problem is however that I have no C programming skills so I am unable to help directly.

I had hoped that I could create some "duct tape" which would help a few people out getting automatic motion-triggered lighting working in the mean-time. Eventually as the respond to events in improved this would no longer be necessary. At the moment I have misterhouse, interfaced over sockets to the DCE router, which is quite untitdy as I have to map X10 codes to device ids in there too.

I'm basically just looking for advice to help me create this duct-tape. I am also happy to make suggestions for improvements to the Lighting Plugin and help out with testing, Wiki writing etc. It's not one or the other.

Regards,

Chris



Hi,

I'm not sure why you call your current solution as "duct tape" and untidy. I'm not sure what exactly do you mean by automatic lighting - if you mean motion triggered lighting only, than you're probably ok with event handling under LMCE. But if you're after more advanced presence/lighting features, than I think Misterhouse has some automatic lighting module that is quite complex, but does things in more advanced fashion. If you'll wait for anything similar in LMCE, then you'll probably wait for a loooong time... Why don't you try MH module for presence/lighting if you already have connected those two systems ?

Your situation is exactly my point of discussion. Only few developers are currently able to do something in C++, majority of users wish to customize behaviour. There is now common reasoning going on these forums that everything that is not written in C++ is a duct tape solution. I disagree, cause if you take a look from that perspective than also all drivers currently in Ruby could be declared for duct tape solutions.... I believe that open source systems are about freedom. Everything is allowed, use your imagination and do what you need...

If you'll try to do it in Ruby, than you'll probably study a lot of existing GSD examples...

HTH,

regards,

Bulek.
Thanks in advance,

regards,

Bulek.

Zaerc

  • Alumni
  • LinuxMCE God
  • *
  • Posts: 2256
  • Department of Redundancy Department.
    • View Profile
Re: Coding an Automatic Lighting controller in GSD
« Reply #23 on: January 19, 2009, 11:14:50 am »
Thom is right, of course, that we have the respond to events in the web admin and we should just extend that.

My problem is however that I have no C programming skills so I am unable to help directly.

I had hoped that I could create some "duct tape" which would help a few people out getting automatic motion-triggered lighting working in the mean-time. Eventually as the respond to events in improved this would no longer be necessary. At the moment I have misterhouse, interfaced over sockets to the DCE router, which is quite untitdy as I have to map X10 codes to device ids in there too.

I'm basically just looking for advice to help me create this duct-tape. I am also happy to make suggestions for improvements to the Lighting Plugin and help out with testing, Wiki writing etc. It's not one or the other.

Regards,

Chris



Hi,

I'm not sure why you call your current solution as "duct tape" and untidy. I'm not sure what exactly do you mean by automatic lighting - if you mean motion triggered lighting only, than you're probably ok with event handling under LMCE. But if you're after more advanced presence/lighting features, than I think Misterhouse has some automatic lighting module that is quite complex, but does things in more advanced fashion. If you'll wait for anything similar in LMCE, then you'll probably wait for a loooong time... Why don't you try MH module for presence/lighting if you already have connected those two systems ?

Your situation is exactly my point of discussion. Only few developers are currently able to do something in C++, majority of users wish to customize behaviour. There is now common reasoning going on these forums that everything that is not written in C++ is a duct tape solution. I disagree, cause if you take a look from that perspective than also all drivers currently in Ruby could be declared for duct tape solutions.... I believe that open source systems are about freedom. Everything is allowed, use your imagination and do what you need...

If you'll try to do it in Ruby, than you'll probably study a lot of existing GSD examples...

HTH,

regards,

Bulek.


The few developers that are currently able to do something in C++ are getting really fed up with your bitching.  It's not like this is the only issue there is to fix. 
"Change is inevitable. Progress is optional."
-- Anonymous


hari

  • Administrator
  • LinuxMCE God
  • *****
  • Posts: 2428
    • View Profile
    • ago control
Re: Coding an Automatic Lighting controller in GSD
« Reply #24 on: January 19, 2009, 11:26:14 am »
yeah, we should fix GSD on 0810 first, before even thinking about integrating more scripting stuff.

Quote
But if you're after more advanced presence/lighting features, than I think Misterhouse has some automatic lighting module that is quite complex, but does things in more advanced fashion. If you'll wait for anything similar in LMCE, then you'll probably wait for a loooong time...

Maybe you want to elaborate what exactly is missing.

br, Hari
rock your home - http://www.agocontrol.com home automation

bulek

  • Administrator
  • wants to work for LinuxMCE
  • *****
  • Posts: 909
  • Living with LMCE
    • View Profile
Re: Coding an Automatic Lighting controller in GSD
« Reply #25 on: January 19, 2009, 11:50:41 am »
yeah, we should fix GSD on 0810 first, before even thinking about integrating more scripting stuff.

Quote
But if you're after more advanced presence/lighting features, than I think Misterhouse has some automatic lighting module that is quite complex, but does things in more advanced fashion. If you'll wait for anything similar in LMCE, then you'll probably wait for a loooong time...

Maybe you want to elaborate what exactly is missing.

br, Hari

Hi,

the main problem with simple motion detected lighting is that sometimes users sits down doing nothing and light comes off...

I don't know internals of MH implementation very deep, but I know that there is somekind of graph you define (nodes, connections). There are also doors sensors and any other indicating user presence or movement  involved...

Basically that module estimates room occupancy based on informations from sensors, tracks user movements and sets lighting accordindly...

But don't get me wrong, this is probably really specific module that will probably be not needed by majority of users...But fellow user asked about it.  So I'm not saying that it should be imlemented, but it will probably not be available in short time...

Zaerc: I always express gratitude for all work of "developers that can do in C++" and I meant nothing bad about it, just indicating that developers' resources are really limited...

Regards,

Bulek.
Thanks in advance,

regards,

Bulek.

Zaerc

  • Alumni
  • LinuxMCE God
  • *
  • Posts: 2256
  • Department of Redundancy Department.
    • View Profile
Re: Coding an Automatic Lighting controller in GSD
« Reply #26 on: January 19, 2009, 12:45:29 pm »
...
the main problem with simple motion detected lighting is that sometimes users sits down doing nothing and light comes off...
...

Have you even bothered to open a ticket for this in trac?  Or does that require C++ skills too?

...
Zaerc: I always express gratitude for all work of "developers that can do in C++" and I meant nothing bad about it, just indicating that developers' resources are really limited...
...

And here is how you express that grattitude:

...
If you'll wait for anything similar in LMCE, then you'll probably wait for a loooong time...
...

Gee thanks, sounds like you're really taking our limited resources into account there.

Just to make things clear, we are not here just to cater to your wishes.  Either help out, or go sit on your ass and wait, but whatever you do quit bitching about duct-taping misterhouse on top of lmce, it is getting really old by now and we have way bigger fish to fry then your fucking light not staying on as long as you'd like, in case you haven't noticed.

Sorry for the harsh words, and I have tried to stay out of this as long as I could but enough is enough.
"Change is inevitable. Progress is optional."
-- Anonymous


chrisbirkinshaw

  • Guru
  • ****
  • Posts: 431
    • View Profile
Re: Coding an Automatic Lighting controller in GSD
« Reply #27 on: January 19, 2009, 08:02:10 pm »
Ok, given the last few posts I suggest we close this thread as follows:

I will:

1. Submit to trac bugs or feature requests for everything in the Lighting Plugin which I would need changing to get a decent automated lighting system based on occupancy and taking into account whether you are watching media etc.

2. Write a small and lightweight script to satisfy my needs in the interim period which connects via sockets

3. Write a wiki page containing the script and explaining all the things I have submitted to Trac and how these will negate the need for it and build on it in terms of usability and expandability

Does this sound reasonable?

tschak909

  • LinuxMCE God
  • ****
  • Posts: 5549
  • DOES work for LinuxMCE.
    • View Profile
Re: Coding an Automatic Lighting controller in GSD
« Reply #28 on: January 19, 2009, 08:30:50 pm »
Yes.

-Thom

chrisbirkinshaw

  • Guru
  • ****
  • Posts: 431
    • View Profile
Re: Coding an Automatic Lighting controller in GSD
« Reply #29 on: January 22, 2009, 09:25:09 pm »

I'm having a problem with ruby code and wondered if anyone can help. This is what I have so far as a test (forgive my first attempts at programming a ruby script!):

Code: [Select]
require 'socket'
include Socket::Constants 

device_id=162
 
def connect_lmce(device_id)
  in_socket = Socket.new( AF_INET, SOCK_STREAM, 0 )
  in_sockaddr = Socket.pack_sockaddr_in( 3450, 'localhost' )
  in_socket.connect( in_sockaddr )

  out_socket = Socket.new( AF_INET, SOCK_STREAM, 0 )
  out_sockaddr = Socket.pack_sockaddr_in( 3450, 'localhost' )
  out_socket.connect( out_sockaddr )

  puts "Setting receiving connection"
  in_socket.send("COMMAND #{device_id}\n",0)
  puts in_socket.recv( 100 )
   
  puts "Setting up sending connection"
  out_socket.send("EVENT #{device_id}\n",0)
  puts out_socket.recv( 100 )
     
  sleep 1

  puts "Registering for plain text messages"
  out_socket.send("PLAIN_TEXT\n",0)
  puts out_socket.recv( 100 )
 
  puts "Finished initialising"
  return in_socket, out_socket
end
 
def register_messages(device_id, in_socket, out_socket)
  puts "Registering for message intercepts (lighting devices)"
  out_socket.send("MESSAGET 24 \n #{device_id} -1000 8 0 5 2 4 84\n",0)
  puts out_socket.recv(100)
   
  puts "Registering for message intercepts (security devices)"
  out_socket.send("MESSAGET 24 \n #{device_id} -1000 8 0 5 1 4 73 \n",0)
  puts out_socket.recv(100)
   
  puts "Finished registration"
end
     
in_socket, out_socket = connect_lmce(device_id)
register_messages(device_id, in_socket, out_socket)
   
messageCount = 0
while data = in_socket.recv( 100 )
  data = data.gsub('"', '').gsub('&', '')
  if data.size > 0
    messageCount += 1
    puts "Received message #{messageCount}: #{data}"
  else
    puts "empty"
  end
end


The last part is of most interest:

Code: [Select]
messageCount = 0
while data = in_socket.recv( 100 )
  data = data.gsub('"', '').gsub('&', '')
  if data.size > 0
    messageCount += 1
    puts "Received message #{messageCount}: #{data}"
  else
    puts "empty"
  end
end

Basically I put the empty check in because I am seeing some weird stuff going on. When I run the script everything works fine while receiving certain messages, but then when one particular kind of message is received the program freezes for 15 secs, then goes into a crazy loop of empty messages. Like this:

Code: [Select]
Finished registration
Received message 1: MESSAGET 18
1234 162 999 9999
Received message 2: MESSAGET 18
1234 162 999 9999
Received message 3: MESSAGET 18
1234 162 999 9999
Received message 4: MESSAGET 35
0 162 9 0  82 -1000 2 9 25 0 
empty
empty
empty
empty
...

Can anyone help me out here?

Thanks,

Chris