<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
    <channel>
        <title>Homeautomation on dotnet.work</title>
        <link>https://dotnet.work/categories/homeautomation/</link>
        <description>Recent content in Homeautomation on dotnet.work</description>
        <generator>Hugo -- gohugo.io</generator>
        <language>en-US</language>
        <managingEditor>dotnet@oles.cloud (Ole Albers)</managingEditor>
        <webMaster>dotnet@oles.cloud (Ole Albers)</webMaster>
        <copyright>Ole Albers</copyright>
        <lastBuildDate>Sat, 20 Jan 2024 12:00:00 +0100</lastBuildDate><atom:link href="https://dotnet.work/categories/homeautomation/index.xml" rel="self" type="application/rss+xml" /><item>
            <title>Setting single Panels on NanoLeaf using Home Assistant</title>
            <link>https://dotnet.work/blog/nanoleaf/</link>
            <pubDate>Sat, 20 Jan 2024 12:00:00 +0100</pubDate><author>dotnet@oles.cloud (Ole Albers)</author>
            <guid>https://dotnet.work/blog/nanoleaf/</guid>
            <description>&lt;p&gt;I went deep into Home Assistant automation currently and - as everybody knows who ever went this road - more ideas came up. So my newest idea was to use the Hex-Panels from Nanoleaf to display some information. For example if the washing machine is ready, I have an appointment, the Smartphone Battery gets low and so on.&lt;/p&gt;&#xA;&lt;!-- image missing: https://github.com/Guacam-Ole/dotnetwork/assets/4692497/eaa1c25f-8b92-420c-b71d-0eee8d6758ab (NanoLeaf with different Colors on the wall) --&gt;&#xA;&lt;p&gt;This entry describes how I managed to do that.&lt;/p&gt;&#xA;&lt;p&gt;&lt;em&gt;I collected all this information from different sources. THe most important was from sygys who posted the Home Assistant configuration: &lt;a class=&#34;link&#34; href=&#34;https://community.home-assistant.io/t/nanoleaf-per-tile-light-control-build-in-ha/442720&#34;  target=&#34;_blank&#34; rel=&#34;noopener&#34;&#xA;    &gt;https://community.home-assistant.io/t/nanoleaf-per-tile-light-control-build-in-ha/442720&lt;/a&gt;&#xA;By the API documentation alone I would not have been able to achieve that.&lt;/em&gt;&lt;/p&gt;&#xA;&lt;h2 id=&#34;the-hardware&#34;&gt;&lt;a href=&#34;#the-hardware&#34; class=&#34;header-anchor&#34;&gt;&lt;/a&gt;The hardware&#xA;&lt;/h2&gt;&lt;p&gt;I mostly used Nanoleaf Elements in the wooden design. These cannot display any colors but just lighten up. I like the descent appearance of those. Do not want to create an all-rgb-gaming-experience in my living room. I also added three dark black hexagon tiles to it. Those where meant to display the status if needed.&#xA;BTW: The nanoleaf app does not offer any color scenes in this setup because the wooden panels are the &amp;ldquo;main&amp;rdquo; panels. But that does not matter for this scenario.&lt;/p&gt;&#xA;&lt;h2 id=&#34;integrating-in-home-assistant&#34;&gt;&lt;a href=&#34;#integrating-in-home-assistant&#34; class=&#34;header-anchor&#34;&gt;&lt;/a&gt;Integrating in Home Assistant&#xA;&lt;/h2&gt;&lt;p&gt;For the main features I used the standard integration for Home Assistant. That allows detecing swipe controls (another advantage of the wooden panels because you don&amp;rsquo;t see fingerprints there) and start mostly anything what the app allows. Which does NOT include adressing single panels&lt;/p&gt;&#xA;&lt;h2 id=&#34;using-the-api&#34;&gt;&lt;a href=&#34;#using-the-api&#34; class=&#34;header-anchor&#34;&gt;&lt;/a&gt;Using the API&#xA;&lt;/h2&gt;&lt;p&gt;Currently this can only be done by a REST-Api. Initially you need any tool that can send POST - Commands. You can use Curl if you like to work on the shell, or UI-Tools like Postman.&lt;/p&gt;&#xA;&lt;h3 id=&#34;retrieving-a-secret&#34;&gt;&lt;a href=&#34;#retrieving-a-secret&#34; class=&#34;header-anchor&#34;&gt;&lt;/a&gt;Retrieving a secret&#xA;&lt;/h3&gt;&lt;p&gt;The first manual step is to obtain a secret. This is done exactly like when installing the Home Assistant integration. You just pair the Panels by pressing the power button for a few seconds until the LEDs start blnking/moving. Don&amp;rsquo;t worry, this will NOT remove any previous pairings.&#xA;Now while the pairing is active call the following URL:&lt;/p&gt;&#xA;&lt;p&gt;&lt;code&gt;POST http://192.168.178.65:16021/api/v1/new&lt;/code&gt;&lt;/p&gt;&#xA;&lt;p&gt;(replace the IP by the Nanoleaf IP. Should be visible in your Router for example)&lt;/p&gt;&#xA;&lt;p&gt;This will return just a simple value which contains your secret token. This token will remain valid even if you unpower the Nanoleaf. Make sure you store this secret somewhere, you will need it.&lt;/p&gt;&#xA;&lt;h3 id=&#34;retrieve-the-configuration&#34;&gt;&lt;a href=&#34;#retrieve-the-configuration&#34; class=&#34;header-anchor&#34;&gt;&lt;/a&gt;Retrieve the Configuration&#xA;&lt;/h3&gt;&lt;p&gt;Now it is time to test your secret and retrieve the configuration from your Nanoleaf panels. You even can do this in your browser, or still in Postman/Curl:&lt;/p&gt;&#xA;&lt;p&gt;&lt;code&gt;http://192.168.178.65:16021/api/v1/thisisthemagicsecretreturnedbefore/&lt;/code&gt;&lt;/p&gt;&#xA;&lt;p&gt;The most interesting part is the layout/positionData-Part in that response:&lt;/p&gt;&#xA;&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;      &amp;#34;layout&amp;#34;: {&#xA;            &amp;#34;numPanels&amp;#34;: 46,&#xA;            &amp;#34;sideLength&amp;#34;: 0,&#xA;            &amp;#34;positionData&amp;#34;: [&#xA;                {&#xA;                    &amp;#34;panelId&amp;#34;: 8172,&#xA;                    &amp;#34;x&amp;#34;: 301,&#xA;                    &amp;#34;y&amp;#34;: 747,&#xA;                    &amp;#34;o&amp;#34;: 360,&#xA;                    &amp;#34;shapeType&amp;#34;: 15&#xA;                },&#xA;                {&#xA;                    &amp;#34;panelId&amp;#34;: 36653,&#xA;                    &amp;#34;x&amp;#34;: 276,&#xA;                    &amp;#34;y&amp;#34;: 703,&#xA;                    &amp;#34;o&amp;#34;: 300,&#xA;                    &amp;#34;shapeType&amp;#34;: 15&#xA;                },&#xA;[..]&#xA;&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;I honestly was a bit surprised, because I do NOT have 46 panels. Far from it. The simple truth is: THe wooden Panels have 6 LEDs. each of them has their own ID. So having 7 wooden panels that makes 42 Ids, additional 3 Ids for the three black panels and the control buttons is an additional panel (with id 0)&lt;/p&gt;&#xA;&lt;p&gt;If you do not need to adress all Panels but just a single one, a good hint is to just rotate one of the panels, make that call again and see which panel has a new orientation (&amp;ldquo;o&amp;rdquo; in the json)&lt;/p&gt;&#xA;&lt;p&gt;Now you have to write down all PanelIds. At least those you want to modifiy. Because I mostly want to use the black panels I split the following part in two, but you can also work with one (or even more).&lt;/p&gt;&#xA;&lt;h3 id=&#34;configure-rest-in-home-assistant&#34;&gt;&lt;a href=&#34;#configure-rest-in-home-assistant&#34; class=&#34;header-anchor&#34;&gt;&lt;/a&gt;Configure Rest in Home Assistant&#xA;&lt;/h3&gt;&lt;p&gt;Go to your beloved Home Assistant Configuration (configuration.yaml) and add the following entries:&#xA;{% raw %}&lt;/p&gt;&#xA;&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;rest_command:&#xA;  nanoleaf_wood:&#xA;    url: http://192.168.178.65:16021/api/v1/thisisthemagicsecretreturnedbefore/effects&#xA;    method: PUT&#xA;    payload: &amp;gt;&#xA;      { &amp;#34;write&amp;#34; : {&amp;#34;command&amp;#34;: &amp;#34;display&amp;#34;, &amp;#34;animType&amp;#34;: &amp;#34;static&amp;#34;, &amp;#34;animData&amp;#34;:&#xA;      {%- set all = [ 8172,36653,  32365,61100,6889,35368,57498,28763,33051,4570,9112,45913,61802,25003,37099,42,14434,43171,34741,29680,58161,4721,33456,45298,4960,8482,45539,16547,53346,9255,5361,58801,30064,33077,4596,57524,54769,50577,21840,42000,13521,1683] %}&#xA;      {%- set ns = namespace(panels=[panels | count | string]) %}&#xA;      {%- for panel in panels %}&#xA;      {%- set ns.panels = ns.panels + [ &amp;#39;{} 1 {} {} {} 0 20&amp;#39;.format(all[panel.number-1], panel.r, panel.g, panel.b) ] %}&#xA;      {%- endfor %}&#xA;      &amp;#34;{{ ns.panels | join(&amp;#39; &amp;#39;) }}&amp;#34;,&#xA;      &amp;#34;loop&amp;#34;: false, &amp;#34;palette&amp;#34;: [], &amp;#34;colorType&amp;#34;: &amp;#34;HSB&amp;#34;}&#xA;      }&#xA;    content_type: &amp;#34;application/json&amp;#34;&#xA;  nanoleaf_black:&#xA;    url: http://192.168.178.65:16021/api/v1/thisisthemagicsecretreturnedbefore/effects&#xA;    method: PUT&#xA;    payload: &amp;gt;&#xA;      { &amp;#34;write&amp;#34; : {&amp;#34;command&amp;#34;: &amp;#34;display&amp;#34;, &amp;#34;animType&amp;#34;: &amp;#34;static&amp;#34;, &amp;#34;animData&amp;#34;:&#xA;      {%- set all = [ 52732, 44680, 17782 ] %}      &#xA;      {%- set ns = namespace(panels=[panels | count | string]) %}&#xA;      {%- for panel in panels %}&#xA;      {%- set ns.panels = ns.panels + [ &amp;#39;{} 1 {} {} {} 0 20&amp;#39;.format(all[panel.number-1], panel.r, panel.g, panel.b) ] %}&#xA;      {%- endfor %}&#xA;      &amp;#34;{{ ns.panels | join(&amp;#39; &amp;#39;) }}&amp;#34;,&#xA;      &amp;#34;loop&amp;#34;: false, &amp;#34;palette&amp;#34;: [], &amp;#34;colorType&amp;#34;: &amp;#34;HSB&amp;#34;}&#xA;      }&#xA;    content_type: &amp;#34;application/json&amp;#34;&#xA;&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;{% endraw %}&#xA;Replace the IP with your Nenoleaf - IP and the secret with your secret (before &amp;ldquo;/effects&amp;rdquo;). It is up to you if you want one or more different calls. The numbers in the &amp;ldquo;set all&amp;rdquo; - part have to be replaced by the &lt;code&gt;panelId&lt;/code&gt;s you retrieved earlier.&lt;/p&gt;&#xA;&lt;p&gt;What comes next is of course testing your config and then restarting Home Assistant.&lt;/p&gt;&#xA;&lt;h3 id=&#34;automation-examples&#34;&gt;&lt;a href=&#34;#automation-examples&#34; class=&#34;header-anchor&#34;&gt;&lt;/a&gt;Automation Examples&#xA;&lt;/h3&gt;&lt;p&gt;Now you can use this in any automation. The number is the number in the array, starting at 1(!) Example for the simple ones:&lt;/p&gt;&#xA;&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;alias: Nano_BlackTest&#xA;description: &amp;#34;&amp;#34;&#xA;trigger: []&#xA;condition: []&#xA;action:&#xA;  - service: rest_command.nanoleaf_black&#xA;    data:&#xA;      panels:&#xA;        - number: 1&#xA;          r: 255&#xA;          g: 0&#xA;          b: 0&#xA;        - number: 2&#xA;          r: 0&#xA;          g: 255&#xA;          b: 0&#xA;        - number: 3&#xA;          r: 0&#xA;          g: 0&#xA;          b: 255&#xA;mode: single&#xA;`and an example to light up the three wooden panels (remember. Each panel has 6 LEDs):`&#xA;alias: Nano_WoodTest&#xA;description: &amp;#34;&amp;#34;&#xA;trigger: []&#xA;condition: []&#xA;action:&#xA;  - service: rest_command.nanoleaf_wood&#xA;    data:&#xA;      panels:&#xA;        - number: 31&#xA;          r: 255&#xA;          g: 255&#xA;          b: 255&#xA;        - number: 32&#xA;          r: 255&#xA;          g: 255&#xA;          b: 255&#xA;        - number: 33&#xA;          r: 255&#xA;          g: 255&#xA;          b: 255&#xA;        - number: 34&#xA;          r: 255&#xA;          g: 255&#xA;          b: 255&#xA;        - number: 35&#xA;          r: 255&#xA;          g: 255&#xA;          b: 255&#xA;        - number: 36&#xA;          r: 255&#xA;          g: 255&#xA;          b: 255&#xA;        - number: 19&#xA;          r: 255&#xA;          g: 255&#xA;          b: 255&#xA;        - number: 20&#xA;          r: 255&#xA;          g: 255&#xA;          b: 255&#xA;        - number: 21&#xA;          r: 255&#xA;          g: 255&#xA;          b: 255&#xA;        - number: 22&#xA;          r: 255&#xA;          g: 255&#xA;          b: 255&#xA;        - number: 23&#xA;          r: 255&#xA;          g: 255&#xA;          b: 255&#xA;        - number: 24&#xA;          r: 255&#xA;          g: 255&#xA;          b: 255&#xA;        - number: 1&#xA;          r: 255&#xA;          g: 255&#xA;          b: 255&#xA;        - number: 2&#xA;          r: 255&#xA;          g: 255&#xA;          b: 255&#xA;        - number: 3&#xA;          r: 255&#xA;          g: 255&#xA;          b: 255&#xA;        - number: 4&#xA;          r: 255&#xA;          g: 255&#xA;          b: 255&#xA;        - number: 5&#xA;          r: 255&#xA;          g: 255&#xA;          b: 255&#xA;        - number: 6&#xA;          r: 255&#xA;          g: 255&#xA;          b: 255&#xA;mode: single&#xA;&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;That&amp;rsquo;s it. Have fun with your panels-&lt;/p&gt;&#xA;</description>
        </item></channel>
</rss>
