<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0">
<channel>
<title>Coder Legion - Recent posts tagged home-automation</title>
<link>https://coderlegion.com/tag/home-automation</link>
<description>Powered by Question2Answer</description>
<item>
<title>Loosely coupled configuration for Home Assistant</title>
<link>https://coderlegion.com/4100/loosely-coupled-configuration-for-home-assistant</link>
<description>&lt;p&gt;This post will be short, but I hope it prove to be useful.&lt;/p&gt;
&lt;p&gt;My home is getting more and more connected, and the number of my automations grows each passing month. Recently, I equipped my roller shutters with connected Somfy engines so they could roll down automatically when it's too hot in summer. Spoiler: given the current heatwave, it's a boon!&lt;/p&gt;
&lt;p&gt;I naively created the following automation configuration:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-yaml&quot;&gt;- id: '1742926520608'
  alias: Close all shutters
  description: Close all shutters if it's already hot in the morning
  triggers:
  - trigger: time                                                      #1
    at: 07:00:00
  conditions:
  - condition: numeric_state
    entity_id: sensor.saint_julien_en_genevois_temperature
    above: 23                                                          #2
  actions:
  - action: cover.close_cover                                          #3
    metadata: {}
    data: {}
    target:
      entity_id: cover.all_shutters                                    #4
  mode: single
&lt;/code&gt;&lt;/pre&gt;
&lt;ol&gt;
&lt;li&gt;If at 7 AM local time&lt;/li&gt;
&lt;li&gt;The temperature where I live is higher than 23°C&lt;/li&gt;
&lt;li&gt;Close&lt;/li&gt;
&lt;li&gt;All shutters&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;Note the entity ID &lt;code&gt;cover.all_shutters&lt;/code&gt;: it's not an out-of-the-box entity. I explicitly created a group for it:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-yaml&quot;&gt;cover:
  - platform: group
    name: &quot;All shutters&quot;
    entities:
      - cover.left_shutter
      - cover.middle_shutter
      - cover.right_shutter
      - cover.bedroom_shutter
      - cover.office_shutter
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;I copied the same approach to switch all the lights off when I leave home. I soon realized there were flaws in this approach.&lt;/p&gt;
&lt;p&gt;While the probability of adding more shutters is pretty low, I'll likely add more smart lights in the future. Every time I add one, I'll need to put it in the group. Also, I added lights in waves; I ID'd the lights in French at first, but later switched to English. As I renamed them all in English to be coherent, I had to update my dashboard to adapt to the new IDs.&lt;/p&gt;
&lt;p&gt;Home Assistant already has everything to cater for the above, &lt;em&gt;Areas&lt;/em&gt;. You can–and you probably should-assign every device to an Area. Once done, you can replace the &lt;code&gt;target&lt;/code&gt; part of the automation with a list of &lt;code&gt;area_id&lt;/code&gt; instead of &lt;code&gt;entity_id&lt;/code&gt;.&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-yaml&quot;&gt;- id: '1742926520608'
  alias: Close all shutters
  description: Close all shutters if it's already hot in the morning
  triggers:
  - trigger: time
    at: 07:00:00
  conditions:
  - condition: numeric_state
    entity_id: sensor.saint_julien_en_genevois_temperature
    above: 23
  actions:
  - action: cover.close_cover
    metadata: {}
    data: {}
    target:
      area_id:                                                         #1
        - office
        - bedroom
        - living_room
  mode: single
&lt;/code&gt;&lt;/pre&gt;
&lt;ol&gt;
&lt;li&gt;Now, Home Assistant closes all shutters that are in any of these areas&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;Areas tend to be much more stable than individual devices. How often do you add a new area to your home? Granted, an area doesn't explicitly map to a room, but I think that's a better approach than my original one. Home Assistant will now manage every new device of the same type added to the area, &lt;em&gt;e.g.&lt;/em&gt;, if you motorize a new shutter or add a new light.&lt;/p&gt;
&lt;p&gt;There's one drawback to this approach. UI Tiles accept only a single entity ID. Thus, if you want to use the GUI, you must create a group as I did in my first approach.&lt;/p&gt;
&lt;p&gt;In this post, I showed how you could replace the explicit grouping of devices by areas. It's the same idea of loose coupling we have in software, but applied to Home Assistant configuration.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;To go further:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a rel=&quot;nofollow&quot; href=&quot;https://www.home-assistant.io/integrations/group/&quot;&gt;Group&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a rel=&quot;nofollow&quot; href=&quot;https://www.home-assistant.io/docs/scripts/perform-actions/#targeting-areas-and-devices&quot;&gt;Targeting areas and devices&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;hr&gt;
&lt;p&gt;&lt;em&gt;Originally published at &lt;a rel=&quot;nofollow&quot; href=&quot;https://blog.frankel.ch/home-assistant/8/&quot;&gt;A Java Geek&lt;/a&gt; on July 13&lt;sup&gt;th&lt;/sup&gt;, 2025&lt;/em&gt;&lt;/p&gt;
</description>
<category>Backend Dev</category>
<guid isPermaLink="true">https://coderlegion.com/4100/loosely-coupled-configuration-for-home-assistant</guid>
<pubDate>Thu, 17 Jul 2025 19:22:03 +0000</pubDate>
</item>
<item>
<title>Getting a single value from a device's state in Home Assistant</title>
<link>https://coderlegion.com/3125/getting-a-single-value-from-a-devices-state-in-home-assistant</link>
<description>&lt;p&gt;I recently acquired &lt;a rel=&quot;nofollow&quot; href=&quot;https://www.netatmo.com/en-eu/additional-smart-radiator-valve&quot;&gt;Netatmo smart radiator valves&lt;/a&gt; to manage my rooms' temperature remotely. I'm not skilled at manual tasks, but I could easily replace the old thermo-static valves. I then registered the smart ones in the Netatmo app. Finally, I integrated them in my Home Assistant via the dedicated &lt;a rel=&quot;nofollow&quot; href=&quot;https://www.home-assistant.io/integrations/netatmo/&quot;&gt;Netatmo integration&lt;/a&gt;. Everything was very straightforward.&lt;/p&gt;
&lt;p&gt;I noticed that each valve not only allows remote control but also offers a state with several attributes. I wanted to extract the room's temperature indicator from it. It was not as easy as I thought it was, so I want to describe how I managed to achieve it.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a rel=&quot;nofollow&quot; href=&quot;https://blog.frankel.ch/home-assistant/1/&quot;&gt;Why Home Assistant?&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a rel=&quot;nofollow&quot; href=&quot;https://blog.frankel.ch/home-assistant/2/&quot;&gt;The Home Assistant model&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a rel=&quot;nofollow&quot; href=&quot;https://blog.frankel.ch/home-assistant/3/&quot;&gt;Replace Philips Hue automation with Home Assistant’s&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a rel=&quot;nofollow&quot; href=&quot;https://blog.frankel.ch/home-assistant/4/&quot;&gt;An example of HACS: Adaptive Lighting&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a rel=&quot;nofollow&quot; href=&quot;https://blog.frankel.ch/home-assistant/5/&quot;&gt;The Home Assistant companion app&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a rel=&quot;nofollow&quot; href=&quot;https://blog.frankel.ch/home-assistant/6/&quot;&gt;Cloudflare Tunnel for Home Assistant&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;By default, the Netatmo valve displays a multi-valued state. To check, go to the Developer Tools &amp;gt; States menu. You can use a filter to find the device.&lt;/p&gt;
&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;&lt;th&gt;Entity &lt;/th&gt;&lt;th&gt;State &lt;/th&gt;&lt;th&gt;Attributes&lt;/th&gt;&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;&lt;td&gt;climate.spare_bedroom +&lt;br&gt;Valve Spare Bedroom &lt;/td&gt;&lt;td&gt;auto &lt;/td&gt;&lt;td&gt;hvac_modes: auto, heat +&lt;br&gt;min_temp: 7 +&lt;br&gt;max_temp: 30 +&lt;br&gt;target_temp_step: 0.5 +&lt;br&gt;preset_modes: away, boost, frost_guard, schedule +&lt;br&gt;current_temperature: 14 +&lt;br&gt;temperature: 7 +&lt;br&gt;hvac_action: idle +&lt;br&gt;preset_mode: frost_guard +&lt;br&gt;selected_schedule: Unknown 67ab635c2dd1afb1e601a8c2 +&lt;br&gt;heating_power_request: 0 +&lt;br&gt;attribution: Data provided by Netatmo +&lt;br&gt;friendly_name: Valve Spare Bedroom +&lt;br&gt;supported_features: 401&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;p&gt;The problem is that the above attributes are not readily usable. We must first extract them individually. For this, we need to create a &lt;em&gt;sensor&lt;/em&gt;; head to File Editor and select &lt;code&gt;configuration.yaml&lt;/code&gt;. Then, append the following snippet:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;template:
  - sensor:
    - unique_id: sensor.spare_bedroom_temperature
      name: &quot;Spare Bedroom Temperature&quot;
      state: &quot;{{ state_attr('climate.spare_bedroom', 'current_temperature') }}&quot; #1
      unit_of_measurement: &quot;°C&quot;
      device_class: temperature                                                 #2
&lt;/code&gt;&lt;/pre&gt;
&lt;ol&gt;
&lt;li&gt;Match the pair entity-attribute above&lt;/li&gt;
&lt;li&gt;Must be &lt;code&gt;temperature&lt;/code&gt; to be used as a temperature sensor afterward&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;Click on Save.&lt;/p&gt;
&lt;p&gt;We don't need to restart Home Assistant, but we must reload the configuration. Click on Developer Tools. Then, click on Check configuration. The new sensor should appear in Settings &amp;gt; Entities.&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://coderlegion.com/?qa=blob&amp;amp;qa_blobid=11469332674979970771&quot; alt=&quot;Home Assistant displaying the new temperature entity&quot;&gt;&lt;/p&gt;
&lt;p&gt;We can now set the Area via the UI to one of the existing areas, in this case, the Spare Bedroom.&lt;/p&gt;
&lt;p&gt;Finally, we can update the Spare Bedroom area in Settings &amp;gt; Area &amp;gt; Spare Bedroom. Set the temperature sensor to the only available item, the sensor we set in the previous steps.&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://coderlegion.com/?qa=blob&amp;amp;qa_blobid=6883075645107495641&quot; alt=&quot;Choose the area's newly-defined temperature sensor&quot;&gt;&lt;/p&gt;
&lt;p&gt;At this point, whenever we add the Area card to a dashboard, Home Assistant displays our newly-created temperature sensor on top of it.&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://coderlegion.com/?qa=blob&amp;amp;qa_blobid=24786768765211516&quot; alt=&quot;Area displaying its temperature&quot;&gt;&lt;/p&gt;
&lt;p&gt;You can use this approach for every State. Check them, and I'm sure you'll get new ideas. For example, every automation has a &lt;code&gt;last_triggered&lt;/code&gt; timestamp attribute.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;To go further:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a rel=&quot;nofollow&quot; href=&quot;https://www.netatmo.com/en-eu/&quot;&gt;Netatmo site&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a rel=&quot;nofollow&quot; href=&quot;https://www.home-assistant.io/integrations/netatmo/&quot;&gt;Netatmo integration&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a rel=&quot;nofollow&quot; href=&quot;https://developers.home-assistant.io/docs/core/entity/sensor/&quot;&gt;Sensor entity&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;hr&gt;
&lt;p&gt;&lt;em&gt;Originally published at &lt;a rel=&quot;nofollow&quot; href=&quot;https://blog.frankel.ch/home-assistant/7/&quot;&gt;A Java Geek&lt;/a&gt; on May 18&lt;sup&gt;th&lt;/sup&gt;, 2025&lt;/em&gt;&lt;/p&gt;
</description>
<category>Java</category>
<guid isPermaLink="true">https://coderlegion.com/3125/getting-a-single-value-from-a-devices-state-in-home-assistant</guid>
<pubDate>Thu, 22 May 2025 06:21:05 +0000</pubDate>
</item>
</channel>
</rss>