Skip to content

Instantly share code, notes, and snippets.

@skx
Created January 3, 2016 07:20
Show Gist options
  • Save skx/ea50198c7891522ffe45 to your computer and use it in GitHub Desktop.
Save skx/ea50198c7891522ffe45 to your computer and use it in GitHub Desktop.
package Power::Outlet::Osram;
use strict;
use warnings;
use base qw{Power::Outlet::Common::IP};
use Device::Osram::Lightify::Hub;
our $VERSION='0.16';
=head1 NAME
Power::Outlet::Osram - Control and query an Osram Lightify light
=head1 SYNOPSIS
my $outlet=Power::Outlet::Osram->new(host => "192.168.1.10", name=>"hall");
print $outlet->query, "\n";
print $outlet->on, "\n";
print $outlet->off, "\n";
=head1 DESCRIPTION
Power::Outlet::Osram is a package for controlling and querying a light on an Osram Lightify network attached bridge.
=head1 USAGE
use Power::Outlet::Osram;
my $lamp=Power::Outlet::Hue->new(host=>"mybridge", name=>"hall");
print $lamp->on, "\n";
=head1 CONSTRUCTOR
=head2 new
my $outlet=Power::Outlet->new(type=>"Osram", host=>"192.168.10.136", name => "Hall" );
my $outlet=Power::Outlet::Osram->new(host=>"mybridge", name="kitchen");
=head1 PROPERTIES
=head2 name
Name for the particular light as configured in the Osram Lightify Bridge
=cut
sub name {
my $self=shift;
$self->{"name"}=shift if @_;
return $self->{"name"};
}
=head1 METHODS
=head2 query
Return the current state of the specified device, as a string.
=cut
sub query {
my $self=shift;
my $x = Device::Osram::Lightify::Hub->new( host => $self->host() );
foreach my $device ( $x->lights() )
{
if ( $device->name() eq $self->name() )
{
return( $device->stringify() );
}
}
}
=head2 on
Sends a message to the device to Turn Power ON
=cut
sub on {
my $self = shift;
return $self->_call("on");
}
=head2 off
Sends a message to the device to Turn Power OFF
=cut
sub off {
my $self = shift;
return $self->_call("off");
}
sub _call {
my $self = shift;
my $state = shift;
my $x = Device::Osram::Lightify::Hub->new( host => $self->host() );
foreach my $device ( $x->lights() )
{
if ( $device->name() eq $self->name() )
{
if ( $state =~ /on/i ) {
$device->on();
return;
}
if ( $state =~ /off/i ) {
$device->off();
return;
}
}
}
}
=head2 switch
Queries the device for the current status and then requests the opposite.
=cut
#see Power::Outlet::Common->switch
=head2 cycle
Sends messages to the device to Cycle Power (ON-OFF-ON or OFF-ON-OFF).
=cut
#see Power::Outlet::Common->cycle
=head1 BUGS
Please log on RT and send an email to the author.
=head1 SUPPORT
DavisNetworks.com supports all Perl applications including this package.
=head1 AUTHOR
Michael R. Davis
CPAN ID: MRDVT
DavisNetworks.com
=head1 COPYRIGHT
Copyright (c) 2013 Michael R. Davis
This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
The full text of the license can be found in the LICENSE file included with this module.
=head1 SEE ALSO
L<http://www.developers.meethue.com/philips-hue-api>, L<http://steveyo.github.io/Hue-Emulator/>
=cut
1;
@skx
Copy link
Author

skx commented Jan 3, 2016

Tested via:

    perl -Ilib/ scripts/power-outlet  Osram ON host 192.168.10.136  name hall

    perl -Ilib/ scripts/power-outlet  Osram OFF host 192.168.10.136  name kitchen

That controls the light named hall or kitchen, via the bridge at 192.168.10.136.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment