How to get the Hash-Id of an item

View: New views
4 Messages — Rating Filter:   Alert me  

How to get the Hash-Id of an item

by Thorsten Weiss :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hello Everybody.

I've written a small perl script which connect MH to the fhem-server Link

I can send data to fhem and i can receive data from fhem.

Now i would set the states of my MH-Items when i receive a fhem message.

The received message looks like this example:

06/09/2009 16:04:21 fhem received data: FS20 Fernseher off ---

FS20 is the object type
Fernseher is the object name
off is the object state

Here is my check for data sub:

sub check_for_data {
#Daten  mitloggen----------------------------------------
if (my $data = said $FHZ_data) {
    my @fhz1000_data = split (" ", $data);
    if ($fhz1000_data[3] eq undef) {
    $fhz1000_data[3] = '---'
    }  
    &::print_log( "fhem received data: $fhz1000_data[0] $fhz1000_data[1] $fhz1000_data[2] $fhz1000_data[3] \n");
        &FS20ST_Item::set_receive(('$'.$fhz1000_data[1]),$fhz1000_data[2],"fhem");
       
    }    
}


and here the corrosponding set receive method:
sub set_receive {
    my ($self, $state, $set_by) = @_;
    &::print_log("set_receive:", $self, $state, $set_by);
    return if &main::check_for_tied_filters($self, $state, $set_by);
    &Generic_Item::set_states_for_next_pass($self, $state, $set_by);
   
}


but i always get this error and MH restarts:

Can't use string ("$Fernseher") as a HASH ref
Exiting program: normal


I think the problem is this line:

&FS20ST_Item::set_receive(('$'.$fhz1000_data[1]),$fhz1000_data[2],"fhem");

I added the Dollar-sign as string to the name of the object so MH schould use it as Object reference, but it does not work...

My question ist :

How can i use my received Object name "Fernseher" to set the MH-Item $Fernseher to the received state?

Regards,
Thorsten Weiss




                                           

Re: How to get the Hash-Id of an item

by Peter Sjödin :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Thorsten Weiss wrote:
> My question ist :
>
> How can i use my received Object name "Fernseher" to set the MH-Item
> $Fernseher to the received state?

Thorsten,

Have a look at the "eval" function. It should do want you want.

Peter


------------------------------------------------------------------------------
Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day
trial. Simplify your report design, integration and deployment - and focus on
what you do best, core application coding. Discover what's new with
Crystal Reports now.  http://p.sf.net/sfu/bobj-july
________________________________________________________
To unsubscribe from this list, go to: http://sourceforge.net/mail/?group_id=1365


Re: How to get the Hash-Id of an item

by Thorsten Weiss :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Thanks for the hint peter,

so i will try the following code:

i hope it will work...



my $object = eval('$'.$fhz1000_data[1]); #transform the string into a perl command
&FS20ST_Item::set_receive($object,$fhz1000_data[2],"fhem"); #call the function with the perl command



regards,
thorsten

Re: How to get the Hash-Id of an item

by Thorsten Weiss :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message


I got it - but with eval it won't work.

I had to add a additional Hasch to assign the Item name to the Reference.

I will post my Code later here

regards,
thorsten.