Last active
January 28, 2025 10:34
-
-
Save rnorth/3bbce8595e48e555eb9c5e18ed16b05a to your computer and use it in GitHub Desktop.
Home Assistant pyscript to mass-update device areas
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import homeassistant | |
@service | |
def update_device_areas(): | |
devreg = homeassistant.helpers.device_registry.async_get(hass) | |
entreg = homeassistant.helpers.entity_registry.async_get(hass) | |
areareg = homeassistant.helpers.area_registry.async_get(hass) | |
area_ids = [] | |
for a in areareg.areas.items(): | |
id = a[0] | |
entry = a[1] | |
log.debug(f"Area: {entry.id} {entry.name}") | |
area_ids.append(entry.id) | |
for d in devreg.devices.items(): | |
id = d[0] | |
entry = d[1] | |
log.debug(f"Device: {entry.name} {entry.area_id}") | |
for area_id in area_ids: | |
if area_id in entry.name and entry.area_id == None: | |
log.info(f"Will put device {entry.name} into area {area_id}") | |
# Uncomment the line below when you're happy that the script will make the correct changes | |
# devreg.async_update_device(device_id=id, area_id=area_id) |
Hi,Sorry for the slow reply, and thanks for looking at this script! I think that actually that view of the logs only shows warnings and errors - not info level. When I want to view logs, I tend to use the vscode extension and look at the homeassistant.log file in the /config directory.I hope this helps!On 16 Apr 2023, at 16:46, Mark Bonnekessel ***@***.***> wrote:Re: ***@***.*** commented on this gist.Thanks for sharing that script!I am new to Home Assistant and have problems finding the logs. I do not find any output in the log under settings -> system -> logs.Info log should be logged without special configuration, shouldn't it?—Reply to this email directly, view it on GitHub or unsubscribe.You are receiving this email because you authored the thread.Triage notifications on the go with GitHub Mobile for iOS or Android.
Thanks for your help. I do not see any log messages from the script in the config/homeassistant.log, even if i change the logging to warn in your script :/
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thanks for sharing that script!
I am new to Home Assistant and have problems finding the logs. I do not find any output in the log under settings -> system -> logs.
Info log should be logged without special configuration, shouldn't it?