{"id":366,"date":"2020-03-30T20:16:32","date_gmt":"2020-03-31T01:16:32","guid":{"rendered":"https:\/\/sundrysites.com\/?page_id=366"},"modified":"2020-03-30T20:16:32","modified_gmt":"2020-03-31T01:16:32","slug":"venstar-runtimes-perl-program","status":"publish","type":"page","link":"https:\/\/sundrysites.com\/index.php\/home-info\/arduino-projects\/perl-programs\/venstar-runtimes-perl-program\/","title":{"rendered":"Venstar Runtimes Perl Program"},"content":{"rendered":"\n<p>The Venstar thermostat has a little-known API (application programming interface) that one can use to control and query it.&nbsp; This Perl program gets the daily runtimes for the last week or so that the Venstar keeps and loads them into a file. It also reports runtimes to HCA.&nbsp; This version was uploaded Jan 1, 2016.<\/p>\n\n\n\n<p># venstar-runtimes-2.pl<br>use LWP::UserAgent;<br>my $i;<br>($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime(time);<br>my $venheat1 = &#8220;-1&#8221;;<br>my $vencool1 = &#8220;0&#8221;;<br>my $vents = &#8220;0&#8221;;<br>my $outfile = &#8220;venruntimes.txt&#8221;;&nbsp; #picked up by hca<br>my $outln = &#8220;&#8221;;<br>my $logfile = &#8220;venrunlog.txt&#8221;;&nbsp; #keep a log<br>my $logln = &#8220;time:&#8221; . ($year-100) . sprintf(&#8220;%02d&#8221;,($mon+1)) . sprintf(&#8220;%02d&#8221;,($mday)) . &#8220;:&#8221;;<br>my $workfile = &#8220;venworkh1&#8221; . ($year-100) . &#8220;.txt&#8221;;<br>my $prevyearworkfile = &#8220;venworkh1&#8221; . ($year-101) . &#8220;.txt&#8221;;<br>my $workval = &#8220;-1&#8221;;<br>my $workctr = &#8220;0&#8221;;<br># first open outfile to make sure at least disk is ok &#8211; if not die quickly<br>if (not (open OUTPUT, &#8220;&gt; $outfile&#8221;))<br>{<br>die &#8220;Output file open error: $!&#8221;;<br>}<br># print &#8220;workfile: $workfile\\n&#8221;;<br># print &#8220;pyworkfile: $prevyearworkfile\\n&#8221;;<br># open this year&#8217;s work file and read it into @workarray<br>if (not (open WORKIN, &#8220;$workfile&#8221;))<br>{<br>$outln = &#8220;venrstatus=2\\n&#8221;;<br>print OUTPUT $outln;<br>close OUTPUT;<br>die &#8220;Work file open error: $!&#8221;;<br>}<br>my @workh1array = &lt;WORKIN&gt;;<br>close WORKIN;<br># open last year&#8217;s work file and read it into @pyworkarray<br>if (not (open PYWORKIN, &#8220;$prevyearworkfile&#8221;))<br>{<br>$outln = &#8220;venrstatus=3\\n&#8221;;<br>print OUTPUT $outln;<br>close OUTPUT;<br>die &#8220;Work file open error: $!&#8221;;<br>}<br>my @pyworkh1array = &lt;PYWORKIN&gt;;<br>close PYWORKIN;<br>#&nbsp;&nbsp; &nbsp;print &#8220;wkarray: @workh1array\\n&#8221;;<br># create user agent and request for venstar<br>my $ua = new LWP::UserAgent;<br>my $req = new HTTP::Request &#8216;GET&#8217;,&#8217;http:\/\/192.168.2.148\/query\/runtimes&#8217;;<br># fetch info from venstar<br>my $resp = $ua -&gt; request($req);<br># see if it ended ok<br>if ($resp-&gt;is_success)<br>{<br>my $message = $resp-&gt;decoded_content;<br>#&nbsp;&nbsp;&nbsp; print &#8220;Received reply: $message\\n&#8221;;<br># remove quotes and brackets from venstar decoded response<br>$message =~ tr\/&#8221;\/\/d;<br>$message =~ tr\/{\/\/d;<br>$message =~ tr\/}\/\/d;<br>$message =~ tr\/[\/\/d;<br>$message =~ tr\/]\/\/d;<br>$message =&nbsp; subs $message, 9;&nbsp; # delete the first 9 chars<br>#&nbsp;&nbsp; &nbsp;print &#8220;tempmsg1: $message\\n&#8221;;<br># create an array out of the remaining string using commas and colons<br>my @venrunarray = split \/[,:]\/, $message;<br>#&nbsp;&nbsp; &nbsp;print &#8220;array: @venrunarray\\n&#8221;;<br>my $arraycount = @venrunarray;<br>#&nbsp;&nbsp; &nbsp;print &#8220;element count: $arraycount\\n&#8221;;<\/p>\n\n\n\n<p>open LOGPUT, &#8220;&gt;&gt; $logfile&#8221; or die &#8220;Output file open error: $!&#8221;;<br>print LOGPUT $logln;<br>print LOGPUT @venrunarray;<br>close LOGPUT;<br>my $setcount = $arraycount \/ 16;<br>if ($setcount != 1)&nbsp;&nbsp; #if setcount = 1 must must be starting up, so ignore<br># normally setcount should be 7.&nbsp; We only care about the first 6 of these<br># as the 7th one is for a partial day.&nbsp; There are a total max of 56 elements<br># and each one has 8 pairs of data, so we increment by 16 through the 112 items in the<br>#array.&nbsp; They are in chrono order, the oldest day is the first set.<br>{<br>for ($i = 0; $i &lt; ($setcount &#8211; 1); $i++)<br>{<br>my $epochseconds = $venrunarray[ ($i * 16) + 1 ];<br>($esec,$emin,$ehour,$emday,$emon,$eyear,$ewday,$eyday,$eisdst) = localtime($epochseconds);<br>#&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;print &#8220;eyday:&#8221; . $eyday . &#8220;\\n&#8221;;<br>#&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;print &#8220;yday:&#8221; . $yday . &#8220;\\n&#8221;;<br>#&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;print &#8220;eheat1val:&#8221; . $venrunarray[ ($i * 16) + 3 ] . &#8220;\\n&#8221;;<br># the last heat1 is the previous day&#8217;s, so keep overwriting<br>$venheat1 = $venrunarray[ ($i * 16) + 3 ] . &#8220;\\n&#8221;;<br>if ($eyday lt $yday)&nbsp; # this is the normal case, replace value in runarray<br>{<br>$workh1array[$eyday] = $venrunarray[ ($i * 16) + 3 ] . &#8220;\\n&#8221;;<br>#&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;print &#8220;$eyday lt $yday\\n&#8221;;<br>}<br>else&nbsp; # must be at start of year<br>{<br>#&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;print &#8220;$eyday gt $yday\\n&#8221;;<br>$pyworkh1array[$eyday] = $venrunarray[ ($i * 16) + 3 ] . &#8220;\\n&#8221;;<br>}<br>}<br>#&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;print &#8220;wkarray: @workh1array\\n&#8221;;<br># &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;print &#8220;pywkarray: @pyworkh1array\\n&#8221;;<br>open WORKIN, &#8220;&gt;$workfile&#8221; or die &#8220;Work file open error: $!&#8221;;<br>foreach (@workh1array)<br>{<br>print WORKIN &#8220;$_&#8221;;<br>}<br>close WORKIN;<br>open PYWORKIN, &#8220;&gt;$prevyearworkfile&#8221; or die &#8221; PY Work file open error: $!&#8221;;<br>foreach (@pyworkh1array)<br>{<br>print PYWORKIN &#8220;$_&#8221;;<br>}<br>close PYWORKIN;<br>$thisline = &#8220;venrunts=&#8221; . ($eyear-100) . sprintf(&#8220;%02d&#8221;,($emon+1)) . sprintf(&#8220;%02d&#8221;,($emday)) . &#8220;\\n&#8221;;<br>$outln = $outln . $thisline;<br>$thisline = &#8220;venheat1run=&#8221; . $venheat1;<br>$outln = $outln . $thisline;<br>$thisline = &#8220;vencool1run=&#8221; . $vencool1 .&#8221;\\n&#8221;;<br>$outln = $outln . $thisline;<br>$thisline = &#8220;venrstatus=0\\n&#8221;;<br>$outln = $outln . $thisline;<br>}<br>}&nbsp;&nbsp; &nbsp;# end of good venstar response<br>else<br>{<br>#&nbsp;&nbsp;&nbsp; print &#8220;HTTP POST error code: &#8220;, $resp-&gt;code, &#8220;\\n&#8221;;<br>#&nbsp;&nbsp;&nbsp; print &#8220;HTTP POST error message: &#8220;, $resp-&gt;message, &#8220;\\n&#8221;;<br>$outln = &#8220;venrstatus=1\\n&#8221;;<br>print OUTPUT $outln;<br>close OUTPUT;<br>$logln = &#8220;time:&#8221; . ($year-100) . sprintf(&#8220;%02d&#8221;,($mon+1)) . sprintf(&#8220;%02d&#8221;,($mday)) . &#8220;: venheat1run=-1&#8221; . &#8220;\\n&#8221;;<br>open LOGPUT, &#8220;&gt;&gt; $logfile&#8221; or die &#8220;Output file open error: $!&#8221;;<br>print LOGPUT $logln;<br>close LOGPUT;<br>die &#8220;Venstar HTTP error&#8221;;<br>}<br># finish writing hca file<br>print OUTPUT $outln;<br>close OUTPUT;<br># either good or not, add to log file<br>$thisline = &#8220;venrunts=&#8221; . ($eyear-100) . sprintf(&#8220;%02d&#8221;,($emon+1)) . sprintf(&#8220;%02d&#8221;,($emday));<br>$outln = &#8220;&#8221;;<br>$outln = $outln . $thisline;<br>$thisline = &#8220;venheat1run=&#8221; . $venheat1;<br>$outln = $outln . $thisline;<br>$logln = &#8220;:&#8221; . $outln;<br>open LOGPUT, &#8220;&gt;&gt; $logfile&#8221; or die &#8220;Output file open error: $!&#8221;;<br>print LOGPUT $logln;<br>close LOGPUT;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>The Venstar thermostat has a little-known API (application programming interface) that one can use to control and query it.&nbsp; This Perl program gets the daily runtimes for the last week or so that the Venstar keeps and loads them into a file. It also reports runtimes to HCA.&nbsp; This version was uploaded Jan 1, 2016. &hellip; <a href=\"https:\/\/sundrysites.com\/index.php\/home-info\/arduino-projects\/perl-programs\/venstar-runtimes-perl-program\/\" class=\"more-link\">Continue reading <span class=\"screen-reader-text\">Venstar Runtimes Perl Program<\/span> <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"parent":352,"menu_order":0,"comment_status":"closed","ping_status":"closed","template":"","meta":{"footnotes":""},"class_list":["post-366","page","type-page","status-publish","hentry"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.4 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Venstar Runtimes Perl Program - Sundrysites<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/sundrysites.com\/index.php\/home-info\/arduino-projects\/perl-programs\/venstar-runtimes-perl-program\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Venstar Runtimes Perl Program - Sundrysites\" \/>\n<meta property=\"og:description\" content=\"The Venstar thermostat has a little-known API (application programming interface) that one can use to control and query it.&nbsp; This Perl program gets the daily runtimes for the last week or so that the Venstar keeps and loads them into a file. It also reports runtimes to HCA.&nbsp; This version was uploaded Jan 1, 2016. &hellip; Continue reading Venstar Runtimes Perl Program &rarr;\" \/>\n<meta property=\"og:url\" content=\"https:\/\/sundrysites.com\/index.php\/home-info\/arduino-projects\/perl-programs\/venstar-runtimes-perl-program\/\" \/>\n<meta property=\"og:site_name\" content=\"Sundrysites\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data1\" content=\"4 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/sundrysites.com\\\/index.php\\\/home-info\\\/arduino-projects\\\/perl-programs\\\/venstar-runtimes-perl-program\\\/\",\"url\":\"https:\\\/\\\/sundrysites.com\\\/index.php\\\/home-info\\\/arduino-projects\\\/perl-programs\\\/venstar-runtimes-perl-program\\\/\",\"name\":\"Venstar Runtimes Perl Program - Sundrysites\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/sundrysites.com\\\/#website\"},\"datePublished\":\"2020-03-31T01:16:32+00:00\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/sundrysites.com\\\/index.php\\\/home-info\\\/arduino-projects\\\/perl-programs\\\/venstar-runtimes-perl-program\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/sundrysites.com\\\/index.php\\\/home-info\\\/arduino-projects\\\/perl-programs\\\/venstar-runtimes-perl-program\\\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/sundrysites.com\\\/index.php\\\/home-info\\\/arduino-projects\\\/perl-programs\\\/venstar-runtimes-perl-program\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/sundrysites.com\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Home Info\",\"item\":\"https:\\\/\\\/sundrysites.com\\\/index.php\\\/home-info\\\/\"},{\"@type\":\"ListItem\",\"position\":3,\"name\":\"Arduino Projects\",\"item\":\"https:\\\/\\\/sundrysites.com\\\/index.php\\\/home-info\\\/arduino-projects\\\/\"},{\"@type\":\"ListItem\",\"position\":4,\"name\":\"Perl Programs\",\"item\":\"https:\\\/\\\/sundrysites.com\\\/index.php\\\/home-info\\\/arduino-projects\\\/perl-programs\\\/\"},{\"@type\":\"ListItem\",\"position\":5,\"name\":\"Venstar Runtimes Perl Program\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/sundrysites.com\\\/#website\",\"url\":\"https:\\\/\\\/sundrysites.com\\\/\",\"name\":\"Sundrysites\",\"description\":\"As In Various and Sundry\",\"publisher\":{\"@id\":\"https:\\\/\\\/sundrysites.com\\\/#\\\/schema\\\/person\\\/1e11ce6af1587a3431e57dfc0797ab61\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/sundrysites.com\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":[\"Person\",\"Organization\"],\"@id\":\"https:\\\/\\\/sundrysites.com\\\/#\\\/schema\\\/person\\\/1e11ce6af1587a3431e57dfc0797ab61\",\"name\":\"Wayne Gulden\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/c0392cdfb7826ed5407aad362998bc6dd03fe293560ce15ccc2211357e3cec6e?s=96&d=mm&r=g\",\"url\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/c0392cdfb7826ed5407aad362998bc6dd03fe293560ce15ccc2211357e3cec6e?s=96&d=mm&r=g\",\"contentUrl\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/c0392cdfb7826ed5407aad362998bc6dd03fe293560ce15ccc2211357e3cec6e?s=96&d=mm&r=g\",\"caption\":\"Wayne Gulden\"},\"logo\":{\"@id\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/c0392cdfb7826ed5407aad362998bc6dd03fe293560ce15ccc2211357e3cec6e?s=96&d=mm&r=g\"},\"sameAs\":[\"https:\\\/\\\/sundrysites.com\"]}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Venstar Runtimes Perl Program - Sundrysites","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/sundrysites.com\/index.php\/home-info\/arduino-projects\/perl-programs\/venstar-runtimes-perl-program\/","og_locale":"en_US","og_type":"article","og_title":"Venstar Runtimes Perl Program - Sundrysites","og_description":"The Venstar thermostat has a little-known API (application programming interface) that one can use to control and query it.&nbsp; This Perl program gets the daily runtimes for the last week or so that the Venstar keeps and loads them into a file. It also reports runtimes to HCA.&nbsp; This version was uploaded Jan 1, 2016. &hellip; Continue reading Venstar Runtimes Perl Program &rarr;","og_url":"https:\/\/sundrysites.com\/index.php\/home-info\/arduino-projects\/perl-programs\/venstar-runtimes-perl-program\/","og_site_name":"Sundrysites","twitter_card":"summary_large_image","twitter_misc":{"Est. reading time":"4 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/sundrysites.com\/index.php\/home-info\/arduino-projects\/perl-programs\/venstar-runtimes-perl-program\/","url":"https:\/\/sundrysites.com\/index.php\/home-info\/arduino-projects\/perl-programs\/venstar-runtimes-perl-program\/","name":"Venstar Runtimes Perl Program - Sundrysites","isPartOf":{"@id":"https:\/\/sundrysites.com\/#website"},"datePublished":"2020-03-31T01:16:32+00:00","breadcrumb":{"@id":"https:\/\/sundrysites.com\/index.php\/home-info\/arduino-projects\/perl-programs\/venstar-runtimes-perl-program\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/sundrysites.com\/index.php\/home-info\/arduino-projects\/perl-programs\/venstar-runtimes-perl-program\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/sundrysites.com\/index.php\/home-info\/arduino-projects\/perl-programs\/venstar-runtimes-perl-program\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/sundrysites.com\/"},{"@type":"ListItem","position":2,"name":"Home Info","item":"https:\/\/sundrysites.com\/index.php\/home-info\/"},{"@type":"ListItem","position":3,"name":"Arduino Projects","item":"https:\/\/sundrysites.com\/index.php\/home-info\/arduino-projects\/"},{"@type":"ListItem","position":4,"name":"Perl Programs","item":"https:\/\/sundrysites.com\/index.php\/home-info\/arduino-projects\/perl-programs\/"},{"@type":"ListItem","position":5,"name":"Venstar Runtimes Perl Program"}]},{"@type":"WebSite","@id":"https:\/\/sundrysites.com\/#website","url":"https:\/\/sundrysites.com\/","name":"Sundrysites","description":"As In Various and Sundry","publisher":{"@id":"https:\/\/sundrysites.com\/#\/schema\/person\/1e11ce6af1587a3431e57dfc0797ab61"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/sundrysites.com\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":["Person","Organization"],"@id":"https:\/\/sundrysites.com\/#\/schema\/person\/1e11ce6af1587a3431e57dfc0797ab61","name":"Wayne Gulden","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/secure.gravatar.com\/avatar\/c0392cdfb7826ed5407aad362998bc6dd03fe293560ce15ccc2211357e3cec6e?s=96&d=mm&r=g","url":"https:\/\/secure.gravatar.com\/avatar\/c0392cdfb7826ed5407aad362998bc6dd03fe293560ce15ccc2211357e3cec6e?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/c0392cdfb7826ed5407aad362998bc6dd03fe293560ce15ccc2211357e3cec6e?s=96&d=mm&r=g","caption":"Wayne Gulden"},"logo":{"@id":"https:\/\/secure.gravatar.com\/avatar\/c0392cdfb7826ed5407aad362998bc6dd03fe293560ce15ccc2211357e3cec6e?s=96&d=mm&r=g"},"sameAs":["https:\/\/sundrysites.com"]}]}},"_links":{"self":[{"href":"https:\/\/sundrysites.com\/index.php\/wp-json\/wp\/v2\/pages\/366","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/sundrysites.com\/index.php\/wp-json\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/sundrysites.com\/index.php\/wp-json\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/sundrysites.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/sundrysites.com\/index.php\/wp-json\/wp\/v2\/comments?post=366"}],"version-history":[{"count":1,"href":"https:\/\/sundrysites.com\/index.php\/wp-json\/wp\/v2\/pages\/366\/revisions"}],"predecessor-version":[{"id":367,"href":"https:\/\/sundrysites.com\/index.php\/wp-json\/wp\/v2\/pages\/366\/revisions\/367"}],"up":[{"embeddable":true,"href":"https:\/\/sundrysites.com\/index.php\/wp-json\/wp\/v2\/pages\/352"}],"wp:attachment":[{"href":"https:\/\/sundrysites.com\/index.php\/wp-json\/wp\/v2\/media?parent=366"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}