<?xml version="1.0" encoding="utf-8"?><feed xmlns="http://www.w3.org/2005/Atom" ><generator uri="https://jekyllrb.com/" version="3.9.3">Jekyll</generator><link href="https://soroosh.github.io//feed.xml" rel="self" type="application/atom+xml" /><link href="https://soroosh.github.io//" rel="alternate" type="text/html" /><updated>2024-01-04T21:49:41+00:00</updated><id>https://soroosh.github.io//feed.xml</id><title type="html">good-gui.de</title><subtitle>Code, Science, Math, Physics, Technology, Computer, and more</subtitle><entry><title type="html">Price Calculation</title><link href="https://soroosh.github.io//pages/price-calculator" rel="alternate" type="text/html" title="Price Calculation" /><published>2021-12-11T05:59:02+00:00</published><updated>2021-12-11T05:59:02+00:00</updated><id>https://soroosh.github.io//pages/price_calculator</id><content type="html" xml:base="https://soroosh.github.io//pages/price-calculator">&lt;h3&gt;Price Calculator&lt;/h3&gt;
&lt;p&gt;
    Do you have used items, that you want to sell but don't know what price tag to put on?
    Here, you can calculate a suggested price.&lt;!--more--&gt;
    The item should still be functional.
    The calculated price here is a suggested price.
    There is no guaranty, that it is the best price.
&lt;/p&gt;

&lt;div class=&quot;table-align&quot;&gt;
    &lt;div class=&quot;table-row&quot;&gt;
        &lt;div class=&quot;table-cell&quot;&gt;
            &lt;label for=&quot;newPrice&quot;&gt;Original price:&lt;/label&gt;
        &lt;/div&gt;
        &lt;div class=&quot;table-cell&quot;&gt;
            &lt;input type=&quot;number&quot; onchange=&quot;calculatePrice()&quot; id=&quot;newPrice&quot; size=15&gt;
            &lt;span id=&quot;newPrice-error&quot; class=&quot;error&quot; role=&quot;alert&quot;&gt;&lt;/span&gt;
        &lt;/div&gt;
    &lt;/div&gt;
    &lt;div class=&quot;table-row&quot;&gt;
        &lt;div class=&quot;table-cell&quot;&gt;
            &lt;label for=&quot;age&quot;&gt;Age in years:&lt;/label&gt;
        &lt;/div&gt;
        &lt;div class=&quot;table-cell&quot;&gt;
            &lt;input type=&quot;number&quot; onchange=&quot;calculatePrice()&quot; id=&quot;age&quot; size=15&gt;
            &lt;span id=&quot;age-error&quot; class=&quot;error&quot; role=&quot;alert&quot;&gt;&lt;/span&gt;
        &lt;/div&gt;
    &lt;/div&gt;
    &lt;div class=&quot;table-row&quot;&gt;
        &lt;div class=&quot;table-cell&quot;&gt;
            &lt;label for=&quot;category&quot;&gt;Category:&lt;/label&gt;
        &lt;/div&gt;
        &lt;div class=&quot;table-cell&quot;&gt;
            &lt;input type=&quot;radio&quot; id=&quot;furniture&quot; name=&quot;category&quot; onchange=&quot;changeDevaluation(19)&quot; value=&quot;19&quot;&gt;
            &lt;label for=&quot;furniture&quot;&gt;Furniture&lt;/label&gt;&lt;br&gt;
            &lt;input type=&quot;radio&quot; id=&quot;elec&quot; name=&quot;category&quot; onchange=&quot;changeDevaluation(9)&quot; value=&quot;9&quot;&gt;
            &lt;label for=&quot;elec&quot;&gt;Major appliance&lt;/label&gt;&lt;br&gt;
            &lt;input type=&quot;radio&quot; id=&quot;cElec&quot; name=&quot;category&quot; onchange=&quot;changeDevaluation(5)&quot; value=&quot;5&quot;&gt;
            &lt;label for=&quot;cElec&quot;&gt;Consumer electronic&lt;/label&gt; &lt;br&gt;
            &lt;input type=&quot;radio&quot; id=&quot;other&quot; name=&quot;category&quot; onchange=&quot;enableCustom()&quot;&gt;
            &lt;label for=&quot;other&quot;&gt;Custom&lt;/label&gt;
            &lt;input type=&quot;number&quot; onchange=&quot;calculatePrice()&quot; id=&quot;devaluation&quot; disabled size=6
                aria-label=&quot;Devaluation period in years&quot; aria-live=&quot;off&quot;&gt;
            &lt;span id=&quot;devaluation-error&quot; class=&quot;error&quot; role=&quot;alert&quot;&gt;&lt;/span&gt;&lt;br&gt;
        &lt;/div&gt;
    &lt;/div&gt;
&lt;/div&gt;
&lt;br&gt;
&lt;div id=&quot;suggestedPrice&quot; role=&quot;alert&quot;&gt;&lt;/div&gt;
&lt;br&gt;&lt;br&gt;&lt;br&gt;
&lt;p&gt;
    The equation we use here to calculate the price is:
    $$
        p = n (1 - log_2(\frac{a}{d} + 1))
    $$
    with
    new price &lt;i&gt;n&lt;/i&gt;, age in years &lt;i&gt;a&lt;/i&gt;, and loss in value parameter &lt;i&gt;d&lt;/i&gt;.
    The loss in value parameter is here the time in years it takes a new item to reach a price 0.
    This should depend on the category of item you want to sell.
    A chair will not lose value as fast as a cell phone.
    It also depends on build quality and if the item was well maintained.
    The values that are used here are rough averages.
    For a specific case, &lt;i&gt;d&lt;/i&gt; can be set in the &quot;Custom&quot; category.

&lt;/p&gt;
&lt;script&gt;
    getAndParseValue = function (id) {
        const value = document.getElementById(id).value;
        if (value == null || value == &quot;&quot;) {
            return null;
        }
        const errorElement = document.getElementById(id + &quot;-error&quot;);
        const number = parseFloat(value.replace(&quot;,&quot;, &quot;.&quot;));
        if (isNaN(number) || number &lt; 0) {
            errorElement.innerHTML = &quot;&lt;br&gt;Error - only positive decimal numbers are valid&quot;;
            return null;
        }
        if (errorElement.innerText != &quot;&quot;) {
            errorElement.innerHTML = &quot;&quot;;
        }
        return number;
    }

    calculatePrice = function () {
        const devaluation = getAndParseValue(&quot;devaluation&quot;);
        const newPrice = getAndParseValue(&quot;newPrice&quot;);
        const age = getAndParseValue(&quot;age&quot;);

        if (devaluation == null || age == null || newPrice == null) {
            return;
        }
        let suggestedPrice;
        if (age &gt;= devaluation) {
            suggestedPrice = 0;
        } else {
            suggestedPrice = newPrice * (1.0 - Math.log2(age / devaluation + 1.0));
        }
        const intl = new Intl.NumberFormat('en-US', { &quot;maximumFractionDigits&quot;: 2, &quot;minimumFractionDigits&quot;: 2 });
        document.getElementById(&quot;suggestedPrice&quot;).innerHTML = &quot;Suggested price: &quot; + intl.format(suggestedPrice);
    }

    enableCustom = function () {
        document.getElementById(&quot;devaluation&quot;).removeAttribute(&quot;disabled&quot;);
    }

    changeDevaluation = function (value) {
        const element = document.getElementById(&quot;devaluation&quot;);
        element.value = value;
        element.setAttribute(&quot;disabled&quot;, true);
        calculatePrice();
    }
&lt;/script&gt;</content><author><name></name></author><category term="The Science Guy" /><category term="price" /><category term="2nd hand" /><summary type="html">Price Calculator Do you have used items, that you want to sell but don't know what price tag to put on? Here, you can calculate a suggested price.</summary></entry><entry><title type="html">Baha-í Calendar</title><link href="https://soroosh.github.io//the%20hacker/2021/08/15/badi.html" rel="alternate" type="text/html" title="Baha-í Calendar" /><published>2021-08-15T05:59:02+00:00</published><updated>2021-08-15T05:59:02+00:00</updated><id>https://soroosh.github.io//the%20hacker/2021/08/15/badi</id><content type="html" xml:base="https://soroosh.github.io//the%20hacker/2021/08/15/badi.html">&lt;p&gt;An easy way to add Baha’í dates (Badi Calendar) into a Flutter app is with the open source dart library &lt;a href=&quot;https://github.com/Soroosh/badi_date&quot;&gt;Badi date&lt;/a&gt;. &lt;!--more--&gt;&lt;/p&gt;

&lt;p&gt;To install add the following to the “dependencies” section of &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;pubspec.yaml&lt;/code&gt; file:&lt;/p&gt;

&lt;figure class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;language-yaml&quot; data-lang=&quot;yaml&quot;&gt;&lt;span class=&quot;na&quot;&gt;dependencies&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt;
  &lt;span class=&quot;na&quot;&gt;badi_date&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;^1.0.1&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/figure&gt;

&lt;p&gt;and run &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;flutter pub get&lt;/code&gt; or &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;dart pub get&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;The following shows the library in use:&lt;/p&gt;

&lt;figure class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;language-dart&quot; data-lang=&quot;dart&quot;&gt;&lt;table class=&quot;rouge-table&quot;&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td class=&quot;gutter gl&quot;&gt;&lt;pre class=&quot;lineno&quot;&gt;1
2
3
4
5
6
7
8
9
10
11
&lt;/pre&gt;&lt;/td&gt;&lt;td class=&quot;code&quot;&gt;&lt;pre&gt;&lt;span class=&quot;kn&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;'package:badi_date/badi_date.dart'&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;;&lt;/span&gt;

&lt;span class=&quot;kd&quot;&gt;final&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;date1&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;BadiDate&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nl&quot;&gt;day:&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;nl&quot;&gt;month:&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;nl&quot;&gt;year:&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;178&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;);&lt;/span&gt;
&lt;span class=&quot;kd&quot;&gt;final&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;date2&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;BadiDate&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;fromDate&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;DateTime&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;now&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;());&lt;/span&gt;

&lt;span class=&quot;kd&quot;&gt;final&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;DateTime&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;start&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;date1&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;startDateTime&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;kd&quot;&gt;final&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;DateTime&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;end&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;date1&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;endDateTime&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;kd&quot;&gt;final&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;BahaiHolyDayEnum&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;?&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;holyDay&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;date1&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;holyDay&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;kd&quot;&gt;final&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;bool&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;date2&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;isPeriodOfFast&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;kd&quot;&gt;final&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;bool&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;date2&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;isAyyamIHa&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;kd&quot;&gt;final&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;BadiDate&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;nextHolyDay&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;date2&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;nextHolyDate&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;;&lt;/span&gt;
&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/figure&gt;

&lt;p&gt;In 3 a BadiDate object is created with Badi day, month, and year. In 4 creation with a Dart DateTime is demonstrated. If the optional parameter &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;longitude&lt;/code&gt; and &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;latitude&lt;/code&gt; are set, the library will consider the exact sunset time. If not set, 6pm will be assumed for sunset. 6pm will also be used for the polar regions. 6 and 7 return the begin and the end of the Badi date. If the date is a holyday, 8 will return a non null result.&lt;/p&gt;

&lt;p&gt;The library is used in the open source Baha’i Calendar &lt;a href=&quot;https://play.google.com/store/apps/details?id=de.pezeshki.badidate&quot;&gt;app&lt;/a&gt;.&lt;/p&gt;</content><author><name></name></author><category term="The Hacker" /><category term="library" /><category term="dart" /><category term="app" /><category term="open source" /><category term="Badi" /><category term="Calendar" /><summary type="html">An easy way to add Baha’í dates (Badi Calendar) into a Flutter app is with the open source dart library Badi date.</summary></entry><entry><title type="html">dart-suncalc</title><link href="https://soroosh.github.io//the%20hacker/2021/08/14/suncalc.html" rel="alternate" type="text/html" title="dart-suncalc" /><published>2021-08-14T05:59:02+00:00</published><updated>2021-08-14T05:59:02+00:00</updated><id>https://soroosh.github.io//the%20hacker/2021/08/14/suncalc</id><content type="html" xml:base="https://soroosh.github.io//the%20hacker/2021/08/14/suncalc.html">&lt;p&gt;The open source library &lt;a href=&quot;https://github.com/Soroosh/dart_suncalc&quot;&gt;dart_suncalc&lt;/a&gt; calculates the sun position and can offer sun set and sun rise times for different locations and dates. &lt;!--more--&gt;
It is a port of the JavaScript library &lt;a href=&quot;https://github.com/mourner/suncalc&quot;&gt;suncalc&lt;/a&gt; into Dart and comes with Dart’s sound null-safety.
In addition to sun position it can calculate also the position of the moon.&lt;/p&gt;

&lt;p&gt;The easiest way to install is to add the following to the “dependencies” section of &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;pubspec.yaml&lt;/code&gt; file:&lt;/p&gt;

&lt;figure class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;language-yaml&quot; data-lang=&quot;yaml&quot;&gt;&lt;span class=&quot;na&quot;&gt;dependencies&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt;
  &lt;span class=&quot;na&quot;&gt;dart_suncalc&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;^0.2.1&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/figure&gt;

&lt;p&gt;and run &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;flutter pub get&lt;/code&gt; or &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;dart pub get&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;To use the library you can import it with&lt;/p&gt;

&lt;figure class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;language-dart&quot; data-lang=&quot;dart&quot;&gt;&lt;span class=&quot;kn&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;'package:dart_suncalc/dart_suncalc.dart'&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/figure&gt;

&lt;p&gt;Than you calculate sun light times with the following:&lt;/p&gt;

&lt;figure class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;language-dart&quot; data-lang=&quot;dart&quot;&gt;&lt;table class=&quot;rouge-table&quot;&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td class=&quot;gutter gl&quot;&gt;&lt;pre class=&quot;lineno&quot;&gt;1
2
3
4
&lt;/pre&gt;&lt;/td&gt;&lt;td class=&quot;code&quot;&gt;&lt;pre&gt;&lt;span class=&quot;c1&quot;&gt;// get today's sunlight times for London&lt;/span&gt;
&lt;span class=&quot;kd&quot;&gt;final&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;times&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;SunCalc&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;getTimes&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;date&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;nl&quot;&gt;lat:&lt;/span&gt; &lt;span class=&quot;mf&quot;&gt;51.5&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;nl&quot;&gt;lng:&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;-&lt;/span&gt;&lt;span class=&quot;mf&quot;&gt;0.1&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;);&lt;/span&gt;

&lt;span class=&quot;kd&quot;&gt;final&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;sunrise&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;times&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;sunrise&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;?.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;toLocal&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;();&lt;/span&gt;
&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/figure&gt;

&lt;p&gt;Beside the sunrise time, out of the box you will get the sunset, dawn, dusk, nautical dawn, nautical dusk,
  night, goldenHour, noon, and nadir times. For other times, there is an interface to add additional times:&lt;/p&gt;

&lt;figure class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;language-dart&quot; data-lang=&quot;dart&quot;&gt;&lt;table class=&quot;rouge-table&quot;&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td class=&quot;gutter gl&quot;&gt;&lt;pre class=&quot;lineno&quot;&gt;1
2
3
4
5
6
&lt;/pre&gt;&lt;/td&gt;&lt;td class=&quot;code&quot;&gt;&lt;pre&gt;&lt;span class=&quot;c1&quot;&gt;// set time for sun angle 45 degree&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;SunCalc&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;addTime&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mf&quot;&gt;45.0&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;'45-rise'&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;'45-set'&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;});&lt;/span&gt;
&lt;span class=&quot;c1&quot;&gt;// get sunlight times for London&lt;/span&gt;
&lt;span class=&quot;kd&quot;&gt;final&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;times&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;SunCalc&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;getTimes&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;date&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;nl&quot;&gt;lat:&lt;/span&gt; &lt;span class=&quot;mf&quot;&gt;51.5&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;nl&quot;&gt;lng:&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;-&lt;/span&gt;&lt;span class=&quot;mf&quot;&gt;0.1&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;);&lt;/span&gt;
&lt;span class=&quot;c1&quot;&gt;// get 45.0 degree time in the first half of the day&lt;/span&gt;
&lt;span class=&quot;kd&quot;&gt;final&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;custom&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;times&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;custom&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;'45-rise'&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;];&lt;/span&gt;
&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/figure&gt;

&lt;p&gt;The position of the sun can be calculated with:&lt;/p&gt;

&lt;figure class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;language-dart&quot; data-lang=&quot;dart&quot;&gt;&lt;table class=&quot;rouge-table&quot;&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td class=&quot;gutter gl&quot;&gt;&lt;pre class=&quot;lineno&quot;&gt;1
2
3
4
5
&lt;/pre&gt;&lt;/td&gt;&lt;td class=&quot;code&quot;&gt;&lt;pre&gt;&lt;span class=&quot;c1&quot;&gt;// get position of the sun (azimuth and altitude) at today's sunrise&lt;/span&gt;
&lt;span class=&quot;kd&quot;&gt;final&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;sunrisePos&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;SunCalc&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;getPosition&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;times&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;sunrise&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;nl&quot;&gt;lat:&lt;/span&gt; &lt;span class=&quot;mf&quot;&gt;51.5&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;nl&quot;&gt;lng:&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;-&lt;/span&gt;&lt;span class=&quot;mf&quot;&gt;0.1&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;);&lt;/span&gt;

&lt;span class=&quot;c1&quot;&gt;// get sunrise azimuth in degrees&lt;/span&gt;
&lt;span class=&quot;kd&quot;&gt;final&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;sunriseAzimuth&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;sunrisePos&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;azimuth&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;180&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;/&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;PI&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;;&lt;/span&gt;
&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/figure&gt;</content><author><name></name></author><category term="The Hacker" /><category term="library" /><category term="dart" /><category term="sun position" /><category term="open source" /><summary type="html">The open source library dart_suncalc calculates the sun position and can offer sun set and sun rise times for different locations and dates.</summary></entry><entry><title type="html">Password</title><link href="https://soroosh.github.io//the%20hacker/2021/05/18/password-i1u.html" rel="alternate" type="text/html" title="Password" /><published>2021-05-18T05:59:02+00:00</published><updated>2021-05-18T05:59:02+00:00</updated><id>https://soroosh.github.io//the%20hacker/2021/05/18/password-i1u</id><content type="html" xml:base="https://soroosh.github.io//the%20hacker/2021/05/18/password-i1u.html">&lt;p&gt;Authentication is increasingly becoming important in the internet and as long alternatives are not wide spread, secure passwords are very &lt;!--more--&gt;important. There are several measures to ensure your password is secure like not to use the same password for different services, use a random string, and most important don’t use a password that a random dude on the internet is recommending. Let’s put all these measures aside. The other day, I learned that some people use URLs as password. It is not recommended to do that, but we don’t want to listen to that for a moment, remember that?&lt;/p&gt;

&lt;p&gt;If you are looking for a URL that you can use as a password, you could consider my homepage &lt;a href=&quot;https://www.i1u.de&quot;&gt;www.i1u.de&lt;/a&gt;. It’s brief and you can remember it easily and look if you capitalize some letter, &lt;a href=&quot;https://www.i1u.de&quot;&gt;www.I1U.de&lt;/a&gt; has everything most password validators require: upper and lower case letters, number, special characters, and it has 10 characters. Perfect. 
I’m not saying you should use it as your password. I’m just saying if you do, I don’t mind.&lt;/p&gt;</content><author><name></name></author><category term="The Hacker" /><category term="password" /><summary type="html">Authentication is increasingly becoming important in the internet and as long alternatives are not wide spread, secure passwords are very</summary></entry><entry><title type="html">A Moment Please</title><link href="https://soroosh.github.io//the%20science%20guy/2018/11/15/a-moment-please.html" rel="alternate" type="text/html" title="A Moment Please" /><published>2018-11-15T16:39:02+00:00</published><updated>2018-11-15T16:39:02+00:00</updated><id>https://soroosh.github.io//the%20science%20guy/2018/11/15/a-moment-please</id><content type="html" xml:base="https://soroosh.github.io//the%20science%20guy/2018/11/15/a-moment-please.html">&lt;p&gt;Have you ever been in that situation? Someone asks you: &quot;What time is it?&quot;. 
You start to answer: &quot;It's &lt;span id=&quot;hourNow&quot;&gt;11&lt;/span&gt;, and &lt;span id=&quot;minuteNow&quot;&gt;23&lt;/span&gt; minutes&quot;, &quot;...and &lt;span id=&quot;secondNow&quot;&gt;45&lt;/span&gt; seconds, haha&quot; you are made fun of for beeing precise.&lt;/p&gt;

&lt;p&gt;One of my favorit watch faces on my smart watch is the fuzzy clock, where the approximate time is given.&lt;/p&gt;&lt;!--more--&gt;
&lt;p&gt;
    &lt;div class=&quot;card&quot;&gt;
        &lt;div id=&quot;fuzzy&quot; class=&quot;card-header&quot;&gt;&lt;/div&gt;
    &lt;/div&gt;
&lt;small&gt;&lt;a href=&quot;https://github.com/Soroosh/soroosh.github.io/blob/master/assets/js/fuzzyClock.js&quot;&gt;source code&lt;/a&gt;&lt;/small&gt;&lt;/p&gt;&lt;br/&gt;

&lt;p&gt;From software developer side, it is anoying to have year, month, day, hour, minute, and second all to describe, one thing, time. 
Thank God, we have unix time. 
&lt;a href=&quot;https://en.wikipedia.org/wiki/Unix_timeunix&quot;&gt;Unix time&lt;/a&gt; is a single value. 
A number consisting of 64 ones and zeros (or a decimal integer) to address all seconds from billions of years before the big bang up to billions of years from now.&lt;/p&gt;

&lt;p&gt;
    &lt;div class=&quot;card&quot;&gt;
        &lt;div id=&quot;unixTime&quot; class=&quot;card-header&quot;&gt;&lt;/div&gt;
    &lt;/div&gt;
    &lt;small&gt;&lt;a href=&quot;https://github.com/Soroosh/soroosh.github.io/blob/master/assets/js/moment.js&quot;&gt;source code&lt;/a&gt;&lt;/small&gt;
&lt;/p&gt;&lt;br/&gt;
    


&lt;p&gt;While it's easy to develop software with unix time, it's impractical for everyday use. 
Wouldn't it be nice if we could remove some clutter and have less parameter for time. 
I have given it some thought and tried to come up with something for the time of the day.
What if instead hour, minute and second just have a single number. I call it moment. 
240 moments are a day, as everyone knowes. So one hour is ten moments. 1 moment is 6 minutes. 
In my experience, if someone asks me to wait just one moment, only five minutes not more, I usualy end up waiting 6. 
Hence the name moment. Moments can also be used as fractions. 
If someone does not need a full moment, she can ask for half a moment.&lt;/p&gt;

&lt;p&gt;It turns out, I'm not the first who comes up with an alternative time unit named &lt;a href=&quot;https://en.wikipedia.org/wiki/Moment_(time)&quot;&gt;moment&lt;/a&gt;. 
Not even 240 for a day is something new (citation needed). 
There have been many ideas and suggestions. 
I like 240 moments for a day. It has advantages over &lt;a href=&quot;https://en.wikipedia.org/wiki/Hour#History&quot;&gt;100 for a day&lt;/a&gt;. 
The first advantage is: you can easily convert hour and minute to moments.
For example, 11:30 is 115 moments = hours x 10 + 30 minutes is 5 moments.
The second advantage is 240 can be evenly divided by 3.
So, you can for example say an adult should sleep one third of a day or 80 moments.
100 divided by 3 is 33.33333. Not so nice.&lt;/p&gt;

&lt;p&gt;Don't confuse my moment time unit with &lt;a href=&quot;https://en.wikipedia.org/wiki/24-hour_clock#Military_time&quot;&gt;military time&lt;/a&gt;. 
Military time is horrible for a software developer. 
Military time you can't just add times. 1630 + 30 is not 1660. It's 1700.
But in moments 165 + 5 is equal 170.
It all works out.&lt;/p&gt;

&lt;p&gt;
    &lt;div class=&quot;card&quot;&gt;
        &lt;div id=&quot;moment&quot; class=&quot;card-header&quot;&gt;&lt;/div&gt;
    &lt;/div&gt;
    &lt;small&gt;&lt;a href=&quot;https://github.com/Soroosh/soroosh.github.io/blob/master/assets/js/moment.js&quot;&gt;source code&lt;/a&gt;&lt;/small&gt;
&lt;/p&gt;&lt;br/&gt;
&lt;img src=&quot;/assets/img/momentClock.png&quot; alt=&quot;Moments clock as an analog clock&quot;/&gt;

&lt;script src=&quot;/assets/js/fuzzyClock.js&quot;&gt;&lt;/script&gt;
&lt;script src=&quot;/assets/js/moment.js&quot;&gt;&lt;/script&gt;</content><author><name></name></author><category term="The Science Guy" /><category term="time" /><summary type="html">Have you ever been in that situation? Someone asks you: &quot;What time is it?&quot;. You start to answer: &quot;It's 11, and 23 minutes&quot;, &quot;...and 45 seconds, haha&quot; you are made fun of for beeing precise. One of my favorit watch faces on my smart watch is the fuzzy clock, where the approximate time is given.</summary></entry><entry><title type="html">Light Switch</title><link href="https://soroosh.github.io//the%20hacker/2017/11/01/light-switch.html" rel="alternate" type="text/html" title="Light Switch" /><published>2017-11-01T05:59:02+00:00</published><updated>2017-11-01T05:59:02+00:00</updated><id>https://soroosh.github.io//the%20hacker/2017/11/01/light-switch</id><content type="html" xml:base="https://soroosh.github.io//the%20hacker/2017/11/01/light-switch.html">&lt;p&gt;Smart bulbs and lights are a dream for hackers. There are light switches available for smart bulbs but why buy if you can DIY. My light switch should have two buttons. One to turn on and to make the lights brighter and one to turn off or  darken the lights. If both buttons are pressed the lights should change colors. The new color should be a color from a predefined set of colors. Here, one way to go:&lt;!--more--&gt; You need&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;Smart lights (of course)&lt;/li&gt;
  &lt;li&gt;computer with GPIO (e.g. Raspberry Pi)&lt;/li&gt;
  &lt;li&gt;Two buttons, two LEDs, resistances, cables, optionally a board&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Wire the one button to GPIO 35 and one to 37 and one LED to 38 and one to 40.
&lt;img src=&quot;/assets/img/posts/LightSwitchSmall.png&quot; alt=&quot;Board design&quot; title=&quot;Board design&quot; /&gt;&lt;/p&gt;

&lt;p&gt;The following python script does the job for the Philips Hue system&lt;/p&gt;

&lt;figure class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;language-python&quot; data-lang=&quot;python&quot;&gt;&lt;table class=&quot;rouge-table&quot;&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td class=&quot;gutter gl&quot;&gt;&lt;pre class=&quot;lineno&quot;&gt;1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
&lt;/pre&gt;&lt;/td&gt;&lt;td class=&quot;code&quot;&gt;&lt;pre&gt;&lt;span class=&quot;c1&quot;&gt;#!/usr/bin/python3
&lt;/span&gt;
&lt;span class=&quot;c1&quot;&gt;# Import the required module. 
&lt;/span&gt;&lt;span class=&quot;kn&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;nn&quot;&gt;RPi.GPIO&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;as&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;GPIO&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;time&lt;/span&gt;
&lt;span class=&quot;kn&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;nn&quot;&gt;requests&lt;/span&gt;
&lt;span class=&quot;kn&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;nn&quot;&gt;json&lt;/span&gt;
&lt;span class=&quot;kn&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;nn&quot;&gt;time&lt;/span&gt;

&lt;span class=&quot;c1&quot;&gt;# Set the mode of numbering the pins. 
&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;GPIO&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;setmode&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;GPIO&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;BOARD&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;c1&quot;&gt;# GPIO 38 and 40 is the output. 
&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;GPIO&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;setup&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;38&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;GPIO&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;OUT&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;GPIO&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;setup&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;40&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;GPIO&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;OUT&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;c1&quot;&gt;# GPIO 35 and 37 is the input. 
&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;GPIO&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;setup&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;35&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;GPIO&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;IN&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;GPIO&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;setup&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;37&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;GPIO&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;IN&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;c1&quot;&gt;# Initialise GPIO21 to high (true) so that the LED is off. 
&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;GPIO&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;output&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;40&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;bp&quot;&gt;False&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;GPIO&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;output&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;38&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;bp&quot;&gt;False&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;

&lt;span class=&quot;c1&quot;&gt;# Base URL 
&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;url&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;http://[IP]/api/[TOKEN]/groups/[GROUP ID]&quot;&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;hue_index&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;4&lt;/span&gt;

&lt;span class=&quot;k&quot;&gt;def&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;change_brightnes&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;change&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;):&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;r&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;requests&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;get&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;url&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;brightnes&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;nb&quot;&gt;min&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nb&quot;&gt;int&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;r&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;json&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()[&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;action&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;][&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;bri&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;change&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;),&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;254&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;brightnes&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;
        &lt;span class=&quot;n&quot;&gt;requests&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;put&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;url&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;+&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;/action&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;data&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;json&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;dumps&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;({&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;bri&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;brightnes&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;on&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;bp&quot;&gt;True&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;transitiontime&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;5&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;}))&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;else&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;
        &lt;span class=&quot;n&quot;&gt;requests&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;put&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;url&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;+&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;/action&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;data&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;json&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;dumps&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;({&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;bri&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;on&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;bp&quot;&gt;False&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;transitiontime&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;50&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;}))&lt;/span&gt;

&lt;span class=&quot;k&quot;&gt;def&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;change_hue&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;():&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;global&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;hue_index&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;hues&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;5461&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;10922&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;16384&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;21845&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;25500&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;27306&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;32767&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;38229&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;43690&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;46920&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;49151&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;54612&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;60074&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;requests&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;put&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;url&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;+&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;/action&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;data&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;json&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;dumps&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;({&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;hue&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;hues&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;hue_index&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;],&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;sat&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;254&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;}))&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;hue_index&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;hue_index&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;%&lt;/span&gt; &lt;span class=&quot;nb&quot;&gt;len&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;hues&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;


&lt;span class=&quot;k&quot;&gt;def&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;button_press&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;channel&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;):&lt;/span&gt;  
    &lt;span class=&quot;k&quot;&gt;global&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;start&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;global&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;double&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;led&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;channel&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;3&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;GPIO&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nb&quot;&gt;input&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;channel&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;==&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;
        &lt;span class=&quot;n&quot;&gt;GPIO&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;output&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;led&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;bp&quot;&gt;True&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
        &lt;span class=&quot;n&quot;&gt;double&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;bp&quot;&gt;True&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;GPIO&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nb&quot;&gt;input&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;35&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;==&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;GPIO&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nb&quot;&gt;input&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;37&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;else&lt;/span&gt; &lt;span class=&quot;bp&quot;&gt;False&lt;/span&gt;
        &lt;span class=&quot;n&quot;&gt;start&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;time&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;time&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;GPIO&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nb&quot;&gt;input&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;channel&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;==&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;
        &lt;span class=&quot;n&quot;&gt;elapsed&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;time&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;time&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;start&lt;/span&gt;
        &lt;span class=&quot;n&quot;&gt;GPIO&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;output&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;led&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;bp&quot;&gt;False&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
        &lt;span class=&quot;k&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;double&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;==&lt;/span&gt; &lt;span class=&quot;bp&quot;&gt;True&lt;/span&gt; &lt;span class=&quot;ow&quot;&gt;and&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;GPIO&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nb&quot;&gt;input&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;35&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;GPIO&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nb&quot;&gt;input&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;37&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;==&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;
            &lt;span class=&quot;n&quot;&gt;change_hue&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt;
        &lt;span class=&quot;k&quot;&gt;elif&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;double&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;==&lt;/span&gt; &lt;span class=&quot;bp&quot;&gt;False&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;
            &lt;span class=&quot;n&quot;&gt;sign&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;channel&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;==&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;37&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;else&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;-&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;
            &lt;span class=&quot;n&quot;&gt;change&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;sign&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;elapsed&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;50&lt;/span&gt;
            &lt;span class=&quot;n&quot;&gt;change_brightnes&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;change&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
 
&lt;span class=&quot;n&quot;&gt;GPIO&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;add_event_detect&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;35&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;GPIO&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;BOTH&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;callback&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;button_press&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;GPIO&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;add_event_detect&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;37&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;GPIO&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;BOTH&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;callback&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;button_press&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;

&lt;span class=&quot;k&quot;&gt;try&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;while&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;
        &lt;span class=&quot;n&quot;&gt;time&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;sleep&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;finally&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;
        &lt;span class=&quot;n&quot;&gt;GPIO&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;cleanup&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt;
&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/figure&gt;

&lt;p&gt;The GPIO pins are set up (lines 9-19) and set up the base URL with the IP address to the Hue bridge and the authentication token as well as the ID of the light group that should be controlled (line 22). You can find out on the &lt;a href=&quot;https://www.developers.meethue.com/&quot;&gt;Hue developer page&lt;/a&gt; how to get a token. A function is defined to change the brightness (line 25). The current brightness is requested (line 26) and the new brightness is set as current plus change but not more than the maximum of 254 (line 27).  If the new brightness is greater than 0 the brightness is changed (line 29) otherwise the lights are turned of with a transition time of 5 s (line 31). A function to change colors is defined (line 33) with a set of colors (line 35). The color is set (line 36) and the an index is set that loops through all colors in the set (line 37). And a function for checking the button events is defined (line 40). We assign an LED to the events pin (line 43). If the button event was a press event (line 44) the controll LED is turned on (line 45), we check if both buttons are pressed (line 46), and start the timer (line 47). If the button event was a release event (line 48) the elapsed time since button press is calculated (line 49), the control LED is turned off (line 50), and we check if the other button is pressed (line 51). If so the color is changed (line 52) if not we check if the other button have been pressed while this one was pressed (line 53). Only if it hadn’t a sign is assigned to mark a increase or decrease of brightness (line 54), the change of brightness is calculated depending on how long the button was pressed (line 55), and the brightness is changed (line 56). For each button an event is set for press and release and the just defined function is set as callback (line 58 and 59). A while loop prevents our program to finish by it self (line 62) and we clean up in case of interruption (line 65).&lt;/p&gt;</content><author><name></name></author><category term="The Hacker" /><category term="automation" /><category term="DIY" /><category term="python" /><summary type="html">Smart bulbs and lights are a dream for hackers. There are light switches available for smart bulbs but why buy if you can DIY. My light switch should have two buttons. One to turn on and to make the lights brighter and one to turn off or darken the lights. If both buttons are pressed the lights should change colors. The new color should be a color from a predefined set of colors. Here, one way to go:</summary></entry><entry><title type="html">Turn it down</title><link href="https://soroosh.github.io//the%20hacker/2017/08/16/turn-it-down.html" rel="alternate" type="text/html" title="Turn it down" /><published>2017-08-16T05:59:02+00:00</published><updated>2017-08-16T05:59:02+00:00</updated><id>https://soroosh.github.io//the%20hacker/2017/08/16/turn-it-down</id><content type="html" xml:base="https://soroosh.github.io//the%20hacker/2017/08/16/turn-it-down.html">&lt;p&gt;When I watch TV at nights, I often don’t pay attention on the volume. To avoid angry neighbours, I wrote a python script to turn the volume down on my smart TV. The most difficult part of this task was to find some kind information on the TV API because there is no public documentation.&lt;!--more--&gt; Here is the script for a Philips TV&lt;/p&gt;

&lt;figure class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;language-python&quot; data-lang=&quot;python&quot;&gt;&lt;table class=&quot;rouge-table&quot;&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td class=&quot;gutter gl&quot;&gt;&lt;pre class=&quot;lineno&quot;&gt;1
2
3
4
5
6
7
8
9
10
&lt;/pre&gt;&lt;/td&gt;&lt;td class=&quot;code&quot;&gt;&lt;pre&gt;&lt;span class=&quot;kn&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;nn&quot;&gt;requests&lt;/span&gt;
&lt;span class=&quot;kn&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;nn&quot;&gt;json&lt;/span&gt;
 
&lt;span class=&quot;k&quot;&gt;try&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;r&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;requests&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;get&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;'http://[TV_IP]:1925/1/audio/volume'&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;r&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;json&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()[&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;current&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;10&lt;/span&gt; &lt;span class=&quot;ow&quot;&gt;and&lt;/span&gt; &lt;span class=&quot;ow&quot;&gt;not&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;r&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;json&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()[&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;muted&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]:&lt;/span&gt;
        &lt;span class=&quot;n&quot;&gt;requests&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;post&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;'http://[TV_IP]:1925/1/audio/volume'&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; 
            &lt;span class=&quot;n&quot;&gt;data&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;json&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;dumps&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;({&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;'current'&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;10&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;}))&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;except&lt;/span&gt; &lt;span class=&quot;nb&quot;&gt;OSError&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;
    &lt;span class=&quot;nb&quot;&gt;exit&lt;/span&gt;
&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/figure&gt;

&lt;p&gt;It requests volume information (line 5) and checks if the volume is above 10 and not muted (line 6). If so it will reduce the volume to 10 (line 7). Exceptions need to be caught if the TV is not reachable/ TV is off (line 9). A cron job runs the script every night at 10pm. Create the cron job with &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;crontab -e&lt;/code&gt; and add&lt;br /&gt;
&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;00 22 * * * [path to script]&lt;/code&gt;&lt;br /&gt;
A nice side effect is a visual and audible yet inconspicuous notification for when it turns 10 pm.&lt;/p&gt;</content><author><name></name></author><category term="The Hacker" /><category term="automation" /><category term="python" /><summary type="html">When I watch TV at nights, I often don’t pay attention on the volume. To avoid angry neighbours, I wrote a python script to turn the volume down on my smart TV. The most difficult part of this task was to find some kind information on the TV API because there is no public documentation.</summary></entry><entry><title type="html">And the Nobel Goes To…</title><link href="https://soroosh.github.io//the%20science%20guy/2013/10/18/nobel-goes-to.html" rel="alternate" type="text/html" title="And the Nobel Goes To…" /><published>2013-10-18T05:59:02+00:00</published><updated>2013-10-18T05:59:02+00:00</updated><id>https://soroosh.github.io//the%20science%20guy/2013/10/18/nobel-goes-to</id><content type="html" xml:base="https://soroosh.github.io//the%20science%20guy/2013/10/18/nobel-goes-to.html">&lt;p&gt;This years Nobel prize in chemistry is awarded to Martin Karplus, Michael Levitt, and Arieh Warshel. Three of my fellow computational scientist who worked in the field of quantum mechanics and molecular mechanics simulation. Congratulations from my side. You really deserve that prize. The other day I was telling one of my students that the time for experimentalist is up. They had a good run but from now on we, the computational guys, are the new heros. There is a new sheriff in town.&lt;/p&gt;</content><author><name></name></author><category term="The Science Guy" /><category term="computational science" /><category term="QM/MM" /><summary type="html">This years Nobel prize in chemistry is awarded to Martin Karplus, Michael Levitt, and Arieh Warshel. Three of my fellow computational scientist who worked in the field of quantum mechanics and molecular mechanics simulation. Congratulations from my side. You really deserve that prize. The other day I was telling one of my students that the time for experimentalist is up. They had a good run but from now on we, the computational guys, are the new heros. There is a new sheriff in town.</summary></entry><entry><title type="html">Partition Problems</title><link href="https://soroosh.github.io//the%20computer%20guy/2013/10/16/partition-problems.html" rel="alternate" type="text/html" title="Partition Problems" /><published>2013-10-16T05:59:02+00:00</published><updated>2013-10-16T05:59:02+00:00</updated><id>https://soroosh.github.io//the%20computer%20guy/2013/10/16/partition-problems</id><content type="html" xml:base="https://soroosh.github.io//the%20computer%20guy/2013/10/16/partition-problems.html">&lt;p&gt;We got a new Linux workstation in our lab and guess who had to set it up. I had to change the partitioning of the hard disk and while I was doing that I also updated the software. The software update made a reboot necessary and someone forgot to change the partition table before rebooting. That caused the system not to boot completely. In the file /etc/fstab the partitions where listed with the partition ID instead of the device name. Because the old partitions were deleted the system could not boot them. The system booted / in read only and didn’t allow to change that. So, there was no way to change fstab. It’s not important whose fault it was. We don’t want to point fingers on someone, especially not at me. Here is what I did to save the day.&lt;!--more--&gt;&lt;/p&gt;
&lt;ol&gt;
  &lt;li&gt;Stay calm and don’t panic.&lt;/li&gt;
  &lt;li&gt;Open fstab with:&lt;br /&gt;
&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;vi /etc/fstab&lt;/code&gt;&lt;br /&gt;
The file opens in read only&lt;/li&gt;
  &lt;li&gt;Note down the partition ID and type of the partition that is missing&lt;/li&gt;
  &lt;li&gt;Use fdisk to change the partition ID by typing:&lt;br /&gt;
&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;fdisk disk [identifier]&lt;/code&gt; (e.g. /dev/sdb1)&lt;br /&gt;
&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;x&lt;/code&gt;&lt;br /&gt;
&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;i&lt;/code&gt;&lt;br /&gt;
&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;[partition ID from step 3]&lt;/code&gt;&lt;br /&gt;
&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;w&lt;/code&gt;&lt;/li&gt;
  &lt;li&gt;Make sure that the partition type hasn’t change from what you have from step 3. If you have changed the type while you were partitioning the system, change it back.&lt;/li&gt;
  &lt;li&gt;Reboot&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;That should solve the problem. No data lost. Once the system boots OK you can change the fstab and than change also the partition ID if needed.&lt;/p&gt;</content><author><name></name></author><category term="The Computer Guy" /><category term="help yourself" /><category term="keep calm and do the right thing" /><category term="partitioning" /><category term="problems" /><summary type="html">We got a new Linux workstation in our lab and guess who had to set it up. I had to change the partitioning of the hard disk and while I was doing that I also updated the software. The software update made a reboot necessary and someone forgot to change the partition table before rebooting. That caused the system not to boot completely. In the file /etc/fstab the partitions where listed with the partition ID instead of the device name. Because the old partitions were deleted the system could not boot them. The system booted / in read only and didn’t allow to change that. So, there was no way to change fstab. It’s not important whose fault it was. We don’t want to point fingers on someone, especially not at me. Here is what I did to save the day.</summary></entry><entry><title type="html">What Computer</title><link href="https://soroosh.github.io//the%20computer%20guy/2013/09/08/what-computer.html" rel="alternate" type="text/html" title="What Computer" /><published>2013-09-08T05:59:02+00:00</published><updated>2013-09-08T05:59:02+00:00</updated><id>https://soroosh.github.io//the%20computer%20guy/2013/09/08/what-computer</id><content type="html" xml:base="https://soroosh.github.io//the%20computer%20guy/2013/09/08/what-computer.html">&lt;p&gt;The other day someone asked me what computer we have. What is an appropriate answer to that question? There is obviously the answer “a grey one!”. In the 80s you could answer a 386 PC, a Mac, an Amiga, and so on. But what do you say now? &lt;!--more--&gt; Nowadays even Macs have Intel inside. So what should I say instead the CPU type? Mac user are usually very specific about what computer they have, all the time. Instead losing the laptop, they cannot find the MacBook Air. That does apply to other Apple products, as well. Apple user never look up something on a tablet but on a iPad, they don’t call someone on there phone, instead they send a text with their iPhone, and I don’t have an awesome song on my MP3 player but awful songs on my 3rd generation 32GB iPod touch. So, how do you answer the question what computer you have? Do you say what operation system is running on it? Do you describe the hardware in detail? Or is it the color?&lt;/p&gt;</content><author><name></name></author><category term="The Computer Guy" /><category term="computer name" /><summary type="html">The other day someone asked me what computer we have. What is an appropriate answer to that question? There is obviously the answer “a grey one!”. In the 80s you could answer a 386 PC, a Mac, an Amiga, and so on. But what do you say now?</summary></entry></feed>