diff --git a/HomeAssistant/Refresh-HADeviceRegistry.ps1 b/HomeAssistant/Refresh-HADeviceRegistry.ps1 new file mode 100644 index 0000000..2eafdbb --- /dev/null +++ b/HomeAssistant/Refresh-HADeviceRegistry.ps1 @@ -0,0 +1,47 @@ +Push-Location /srv/ha/current/homeassistant/.storage + +$Count = [ordered]@{ + Devices=[PSCustomObject]([ordered]@{ + Before = -1 + After = -1 + Removed = -1 + }) + Entities=[PSCustomObject]([ordered]@{ + Before = -1 + After = -1 + Removed = -1 + }) +} +$devices = $(Get-Content ./core.device_registry | ConvertFrom-Json -Depth 10) +$Count.Devices.Before = $devices.data.devices.count +$devices.data.devices = $devices.data.devices | +# Where-Object identifiers -notmatch 'zwave' + Where-Object {$_.identifiers[0] -eq 'zha'} +$entities = $(Get-Content ./core.entity_registry | ConvertFrom-Json -Depth 10) +$Count.Entities.Before = $entities.data.entities.count +$entities.data.entities = $entities.data.entities | + Where-Object platform -match 'zha' +# Where-Object platform -notmatch zwave | +# Where-Object { -not ( +# $_.platform -match 'switch' -and $_.entity_id -match 'light\.' -and -not $_.config_entry_id +# ) } + +$Count.Devices.After = $devices.data.devices.count +$Count.Entities.After = $entities.data.entities.count +$Count.Devices.Removed = $Count.Devices.Before - $Count.Devices.After +$Count.Entities.Removed = $Count.Entities.Before - $Count.Entities.After + +$Count | Format-Table + +$devices | ConvertTo-Json -Depth 10 > /tmp/new.core.device_registry +$entities | ConvertTo-Json -Depth 10 > /tmp/new.core.entity_registry + +ha core stop +sudo mv ./core.entity_registry ./core.entity_registry.old +sudo mv ./core.device_registry ./core.device_registry.old +sudo cp /tmp/new.core.entity_registry ./core.entity_registry +sudo cp /tmp/new.core.device_registry ./core.device_registry +Pop-Location + + +ha core start diff --git a/HomeAssistant/_.package.json b/HomeAssistant/_.package.json new file mode 100644 index 0000000..d1fc772 --- /dev/null +++ b/HomeAssistant/_.package.json @@ -0,0 +1,19 @@ +{ + "package": { + "Condition": [ + { + "custom": null, + "System": null, + "Hostname": null, + "Username": null, + "CmdletExists": null, + "AppExeExists": [ + "ha", + "docker" + ], + "Logic": 0 + } + ], + "Name": "HomeAssistant" + } +} diff --git a/HomeAssistant/hass.ps1 b/HomeAssistant/hass.ps1 new file mode 100644 index 0000000..715ace2 --- /dev/null +++ b/HomeAssistant/hass.ps1 @@ -0,0 +1,2 @@ +if( $args ) { docker exec homeassistant hass $args } +else { docker exec homeassistant hass --help }