|
From: H P. <hp...@gm...> - 2025-01-19 16:36:36
|
Misterhouse can now use a local Large Language Model! Thanks to a recent update to HA_Item from Dave, MH can now send a 'perform action’ request to HA and then parse back the results. Master has been updated.
I found an inexpensive used nVidia 3060TI videocard, installed ollama, and connected it to HA via the HA Ollama integration.
With that backend in place, I can make email reports a bit more ‘friendly’. I send out nightly emails on plant moisture levels, which were technically acurate and boring to read. I’ve now sent that text through the LLM to make it more interesting to read. Really easy with the latest integration:
#noloop=start
my $model = "qwen2_5_7b_instruct_q8_0";
my $prompt = "Please summarize the text that follows these instructions for an email report. The text contains information about soil moisture for plants, and the battery level of the sensors. The output should be concise, friendly and easy to understand, including details on how moist the soil is and only report on battery health if it needs to be replaced with less than 50% remaining. The text also includes a date of the last update, only anything older than a day should be noted. Add a bit of humor and add in a random fun fact that has not been used before. Text is as follows:";
my $output = "";
#noloop=stop
$v_print_soil_timer = new Voice_Cmd("Print [sensor1,all] timer data to the log file");
$v_print_soil_data = new Voice_Cmd("[Print,email] ecowitt sensor data");
if (my $state = said $v_print_soil_data) {
my $last_updated;
my $text = "";
my $batt1 = state $sensor1_batt ;
my $batt2 = state $sensor2_batt ;
my $batt3 = state $sensor3_batt ;
my $batt4 = state $sensor4_batt ;
$text .= "1 Plant moisture is " . state $sensor1_moist . " %\n";
$text .= "1 Plant battery is " . $batt1 . " %\n";
$last_updated = $main::Time - $sensor1_moist->get_idle_time();
$text .= "1 Plant Last Updated: " . time_date_stamp(2, $last_updated) . "\n\n";
$text .= "2 Plant moisture is " . state $sensor2_moist . " %\n";
$text .= "2 Plant battery is " . $batt2 . " %\n";
$last_updated = $main::Time - $sensor2_moist->get_idle_time();
$text .= "2 Plant Last Updated: " . time_date_stamp(2, $last_updated) . "\n\n";
$text .= "3 Plant moisture is " . state $sensor3_moist . " %\n";
$text .= "3 Plant battery is " . $batt3 . " %\n";
$last_updated = $main::Time - $sensor3_moist->get_idle_time();
$text .= "3 Plant Last Updated: " . time_date_stamp(2, $last_updated) . "\n\n";
$text .= “4 Tree moisture is " . state $sensor4_moist . " %\n";
$text .= “4 Tree battery is " . $batt4 . " %\n";
$last_updated = $main::Time - $sensor4_moist->get_idle_time();
$text .= "4 Tree Last Updated: " . time_date_stamp(2, $last_updated) . "\n\n";
$text .= "\n";
if (lc $state eq "print") {
print $text;
} else {
if ($use_llm) {
use_ha_llm($prompt,$text, $model);
} else {
net_mail_send(to => ‘<email>', subject => "Plant Soil Status Report", text => $text);
}
}
}
sub use_ha_llm {
my ($prompt, $text, $model) = @_;
$ha_house->ha_perform_action( "conversation.process", {'agent_id'=> "conversation.$model", 'text' => $prompt . " " . $text}, \&use_ha_llm_response_callback, $text );
}
sub use_ha_llm_response_callback {
my ($success, $response, $text ) = @_;
my $email_text = $text;
unless ($success) {
&print_log( "[ecowitt.pl]: Error. Callback did not return success, error response=" . $response );
} else {
$email_text = $response->{response}->{speech}->{plain}->{speech};
$email_text =~ s/[^\x00-\x7f]//g; #strip out any funny characters for sending
}
net_mail_send(to => ‘<email>', subject => "Plant Soil Status Report", text => $email_text);
}
|