{"id":2930,"date":"2017-12-10T14:53:37","date_gmt":"2017-12-10T14:53:37","guid":{"rendered":"http:\/\/grodansparadis.com\/wordpress\/?p=2930"},"modified":"2017-12-10T14:53:37","modified_gmt":"2017-12-10T14:53:37","slug":"vscp-howto-min-max","status":"publish","type":"post","link":"https:\/\/grodansparadis.com\/wordpress\/?p=2930","title":{"rendered":"#VSCP HOWTO: Min\/max"},"content":{"rendered":"<p><a href=\"https:\/\/i0.wp.com\/grodansparadis.com\/wordpress\/wp-content\/uploads\/2017\/08\/vscp_logo_text_box.jpg\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" data-attachment-id=\"2646\" data-permalink=\"https:\/\/grodansparadis.com\/wordpress\/?attachment_id=2646\" data-orig-file=\"https:\/\/i0.wp.com\/grodansparadis.com\/wordpress\/wp-content\/uploads\/2017\/08\/vscp_logo_text_box.jpg?fit=1123%2C794&amp;ssl=1\" data-orig-size=\"1123,794\" data-comments-opened=\"1\" data-image-meta=\"{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}\" data-image-title=\"vscp_logo_text_box\" data-image-description=\"\" data-image-caption=\"\" data-large-file=\"https:\/\/i0.wp.com\/grodansparadis.com\/wordpress\/wp-content\/uploads\/2017\/08\/vscp_logo_text_box.jpg?fit=580%2C410&amp;ssl=1\" class=\"alignnone size-full wp-image-2646\" src=\"https:\/\/i0.wp.com\/grodansparadis.com\/wordpress\/wp-content\/uploads\/2017\/08\/vscp_logo_text_box.jpg?resize=580%2C410\" alt=\"\" width=\"580\" height=\"410\" srcset=\"https:\/\/i0.wp.com\/grodansparadis.com\/wordpress\/wp-content\/uploads\/2017\/08\/vscp_logo_text_box.jpg?w=1123&amp;ssl=1 1123w, https:\/\/i0.wp.com\/grodansparadis.com\/wordpress\/wp-content\/uploads\/2017\/08\/vscp_logo_text_box.jpg?resize=300%2C212&amp;ssl=1 300w, https:\/\/i0.wp.com\/grodansparadis.com\/wordpress\/wp-content\/uploads\/2017\/08\/vscp_logo_text_box.jpg?resize=768%2C543&amp;ssl=1 768w, https:\/\/i0.wp.com\/grodansparadis.com\/wordpress\/wp-content\/uploads\/2017\/08\/vscp_logo_text_box.jpg?resize=1024%2C724&amp;ssl=1 1024w\" sizes=\"auto, (max-width: 580px) 100vw, 580px\" \/><\/a><\/p>\n<p>Quite often one want to store min and max for measurement values\u00a0 So of course you can do that with the VSCP server just by adding a row to the decision matrix.<\/p>\n<p>The first thing you need is a remote variable to store the min\/max in. You can add this remote variable to the variable xml file so it is created when the system starts or add it as a persistent variable to the database. Another way is to create the variable when the server starts right is the DM. We\u00a0 use the last method here as it is makes things clearer in this how-to.<\/p>\n<p>You can create a remote variable <strong>minimum<\/strong> and another <strong>maximum<\/strong> with the following two DM rows which triggers on the\u00a0<a href=\"http:\/\/www.vscp.org\/docs\/vscpspec\/doku.php?id=class2.vscpd#type_23_0x0017_starting_up\">CLASS2.VSCPD, Type=23 Starting up<\/a>\u00a0 which is feed to the DM once when the VSCP server is started. .<\/p>\n<pre>&lt;row enable=\"true\" groupid=\"Min\/max\" &gt;\r\n\r\n&lt;comment&gt;\r\n Create variable that hold min\r\n when the server is started \r\n ( CLASS2.VSCPD, Type=23 ).\r\n &lt;\/comment&gt;\r\n\r\n&lt;mask priority=\"0\"\r\n class=\"0xFFFF\"\r\n type=\"0xFFFF\"\r\n GUID=\" 00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00\" \/&gt;\r\n\r\n&lt;filter priority=\"0\"\r\n class=\"65535\"\r\n type=\"23\"\r\n GUID=\" 00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00\" \/&gt;\r\n\r\n&lt;action&gt;0x50&lt;\/action&gt;\r\n &lt;param&gt;\r\n minimum;float;false;0;0x777;9999999;BASE64:test min\r\n &lt;\/param&gt;\r\n\r\n&lt;\/row&gt;\r\n \r\n &lt;row enable=\"true\" groupid=\"Min\/max\" &gt;\r\n\r\n&lt;comment&gt;\r\n Create variable that hold min\r\n when the server is started ( CLASS2.VSCPD, Type=23 ).\r\n &lt;\/comment&gt;\r\n\r\n&lt;mask priority=\"0\"\r\n class=\"0xFFFF\"\r\n type=\"0xFFFF\"\r\n GUID=\" 00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00\" \/&gt;\r\n\r\n&lt;filter priority=\"0\"\r\n class=\"65535\"\r\n type=\"23\"\r\n GUID=\" 00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00\" \/&gt;\r\n\r\n&lt;action&gt;0x50&lt;\/action&gt;\r\n &lt;param&gt;\r\n maximum;float;false;0;0x777;-999999;BASE64:test max\r\n &lt;\/param&gt;\r\n\r\n&lt;\/row&gt;<\/pre>\n<p>Here the\u00a0\u00a0<strong>minimum<\/strong> variable is created as a non-persistent variable (it will not hold its value between sessions), it is created as a float and initiated to a &#8220;very high&#8221; value (9999999), The <strong>maximum<\/strong> variable is also created as a float and initiated to a &#8220;very low&#8221; number (-999999).<\/p>\n<p>You can read more about the <a href=\"http:\/\/www.vscp.org\/docs\/vscpd\/doku.php?id=vscp_daemon_decision_matrix#store_in_variable\">store remote variable action here.<\/a><\/p>\n<p>The values for the minimum and maximum variables is selected so that minimum is initiated to a value that is higher than what is expected to be a lowest value that will be received by the system and the same for the maximum but the other way around.<\/p>\n<p>So no we have the two variables. Suppose we now want to check the maximum and minimums for a temperature.\u00a0 This means that we will look for a <a href=\"http:\/\/www.vscp.org\/docs\/vscpspec\/doku.php?id=class1.measurement#type_6_0x06_temperature\">measurement event\u00a0 with type = 6 temperature<\/a>.\u00a0 I write &#8220;measurement event&#8221; here as <a href=\"http:\/\/www.vscp.org\/docs\/vscpspec\/doku.php?id=class1.measurement\">they come in a couple of flavors<\/a>.\u00a0 A DM row\u00a0 like the following will handle the collection of minimum data<\/p>\n<pre>&lt;row enable=\"true\" groupid=\"Min\/max\" &gt;\r\n\r\n&lt;comment&gt;\r\n Test for minimum\r\n &lt;\/comment&gt;\r\n\r\n&lt;mask priority=\"0\" \r\n class=\"0xFFFF\" \r\n type=\"0xFFFF\" \r\n GUID=\" 00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00\" \/&gt;\r\n\r\n&lt;filter priority=\"0\" \r\n class=\"10\" \r\n type=\"6\" \r\n GUID=\" 00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00\" \/&gt;\r\n\r\n&lt;action&gt;0x71&lt;\/action&gt;\r\n &lt;param&gt;\r\n minimum;1;1\r\n &lt;\/param&gt;\r\n\r\n&lt;\/row&gt;<\/pre>\n<p>Here we filter on <a href=\"http:\/\/www.vscp.org\/docs\/vscpspec\/doku.php?id=class1.measurement#type_6_0x06_temperature\">CLASS1.MEASUREMENT, Type=6 temperature (class=10, type=6)<\/a> from any sensor (we normally should have selected on by entering a GUID for it).\u00a0 The action 0x71 is the<\/p>\n<pre class=\"code\"><a href=\"http:\/\/www.vscp.org\/docs\/vscpd\/doku.php?id=vscp_daemon_decision_matrix#store_minimum\">VSCP_DAEMON_ACTION_CODE_STORE_MIN<\/a><\/pre>\n<p>and it will store the temperature value of the incoming VSCP event if it is lower than the value currently stored in the remote variable <strong>minimum<\/strong>. The 1,1 after the variable name\u00a0 in the parameter says that the measurement should have unit=1 (Celsius in this case) and originate from sensor with index=1 on the remote node,<\/p>\n<p>For the maximum the DM row looks like<\/p>\n<pre>&lt;row enable=\"true\" groupid=\"Min\/max\" &gt;\r\n\r\n&lt;comment&gt;\r\n Test for maximum\r\n &lt;\/comment&gt;\r\n\r\n&lt;mask priority=\"0\" \r\n class=\"0xFFFF\" \r\n type=\"0xFFFF\" \r\n GUID=\" 00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00\" \/&gt;\r\n\r\n&lt;filter priority=\"0\" \r\n class=\"10\" \r\n type=\"6\" \r\n GUID=\" 00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00\" \/&gt;\r\n\r\n&lt;action&gt;0x72&lt;\/action&gt;\r\n &lt;param&gt;\r\n maximum;1;1\r\n &lt;\/param&gt;\r\n\r\n&lt;\/row&gt;<\/pre>\n<p>The functionality is the same except that the<\/p>\n<pre class=\"code\"><a href=\"http:\/\/www.vscp.org\/docs\/vscpd\/doku.php?id=vscp_daemon_decision_matrix#store_maximum\">VSCP_DAEMON_ACTION_CODE_STORE_MAX<\/a><\/pre>\n<p>action is used here which compares the names variable for a highest value instead of a lowest value.<\/p>\n<p>That it. We now have to variables maximum and minimum that\u00a0 holds the maximum and minimum values for the temperature. We can read (and write) this value in all the interfaces, tcp\/op, websocket, mqtt, REST etc and use it for other calculations or present it in a UI. With websocket this presentation is actual trivial using one of the ready-made widgets.<\/p>\n<p>Also not that this work s for all measurement units (that is all SI defined and derived units)\u00a0 in the same way.\u00a0 No coding needed.<\/p>\n<p>One last thing. Suppose you want to daily maximum\/minimum instead of an all time maximum\/minimum.\u00a0 Easy<\/p>\n<p>Add a DM row that triggers on<\/p>\n<pre class=\"code\"><a href=\"http:\/\/www.vscp.org\/docs\/vscpspec\/doku.php?id=class2.vscpd#type_9_0x0009_midnight\">CLASS2.VSCPD, Type=9 Midnight<\/a><\/pre>\n<p>and store\u00a0 the &#8220;very low&#8221;\/&#8221;very high&#8221; value to the minimum. It is\u00a0harder than that. In the same way you can do this on a <a href=\"http:\/\/www.vscp.org\/docs\/vscpspec\/doku.php?id=class2.vscpd#type_11_0x000b_week\">weekly<\/a>, <a href=\"http:\/\/www.vscp.org\/docs\/vscpspec\/doku.php?id=class2.vscpd#type_12_0x000c_month\">monthly<\/a> etc basis.<\/p>\n<p>You can also use the escapes to\u00a0 create a more dynamic variable that store the daily minimum\/maximum. Try a<a href=\"http:\/\/www.vscp.org\/docs\/vscpd\/doku.php?id=vscp_daemon_decision_matrix#store_in_variable\"> store in variable<\/a><\/p>\n<pre class=\"code\">minimum-<strong>%isodate<\/strong>;float;true;0;0x777;<strong>%variable:[<\/strong><i>minimum<\/i><strong>]<\/strong><\/pre>\n<p>which is set to trigger just before midnight. What you get here is a remote variable <strong>minimum-YYMMDD<\/strong>\u00a0 where YYMMDD is the current date that is persistent and holds the value of the <strong>minimum<\/strong> remote variable collected for that date.<\/p>\n<p>Try that with the rest..<\/p>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Quite often one want to store min and max for measurement values\u00a0 So of course you can do that with the VSCP server just by adding a row to the decision matrix. The first thing you need is a remote variable to store the min\/max in. You can add this remote variable to the variable [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_crdt_document":"","jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":true,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2}},"categories":[53,13],"tags":[],"class_list":["post-2930","post","type-post","status-publish","format-standard","hentry","category-howtos","category-vscp"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_shortlink":"https:\/\/wp.me\/p4raCZ-Lg","jetpack_sharing_enabled":true,"jetpack_likes_enabled":true,"jetpack-related-posts":[],"_links":{"self":[{"href":"https:\/\/grodansparadis.com\/wordpress\/index.php?rest_route=\/wp\/v2\/posts\/2930","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/grodansparadis.com\/wordpress\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/grodansparadis.com\/wordpress\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/grodansparadis.com\/wordpress\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/grodansparadis.com\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=2930"}],"version-history":[{"count":1,"href":"https:\/\/grodansparadis.com\/wordpress\/index.php?rest_route=\/wp\/v2\/posts\/2930\/revisions"}],"predecessor-version":[{"id":2931,"href":"https:\/\/grodansparadis.com\/wordpress\/index.php?rest_route=\/wp\/v2\/posts\/2930\/revisions\/2931"}],"wp:attachment":[{"href":"https:\/\/grodansparadis.com\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=2930"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/grodansparadis.com\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=2930"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/grodansparadis.com\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=2930"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}