Skip to content

Instantly share code, notes, and snippets.

@justusiv
Last active November 12, 2021 02:44
Show Gist options
  • Save justusiv/177c0750a1936486b735a2a2d503e424 to your computer and use it in GitHub Desktop.
Save justusiv/177c0750a1936486b735a2a2d503e424 to your computer and use it in GitHub Desktop.
If your HASS is setup for google assistant you can use this to generate the data for the configuration yaml files. This was quickly created for my own needs but thought i would share. paste into ISE and run. two questions are asked one for IP of wled to pull the json info and the second is for a room. I used Bedroom, not sure if it can handle sp…
if ($wledip -eq $null){$wledip = Read-Host -Prompt "Enter IP of wled"}
if ($location -eq $null){$location = Read-Host -Prompt "Enter location... For example Bedroom... Input"}
$data = (Invoke-WebRequest http://$wledip/json).content
$obj = ConvertFrom-Json -InputObject $data
$effects = $obj.effects
$effects = $effects -replace '&', ' '
$effects = $effects -replace '\+', ' plus'
$effects = $effects -replace ' ', ''
$palettes = $obj.palettes
$palettes = $palettes -replace '\* '
$palettes = $palettes -replace '&', ' '
$palettes = $palettes -replace ' ', ' '
$palettes = $palettes -replace ' ', ' '
$palettes
$count = 0
Write-Warning "FX Put this in your configuration.yaml"
write-host "shell_command:"
foreach ($item in $effects){
write-host " set_fx_to_" -NoNewline
write-host "$count" -NoNewline
write-host ': ' -NoNewline
write-host "'curl "-NoNewline
write-host '"' -NoNewline
write-host "http://$wledip/win&FX=$count" -NoNewline
write-host '"' -NoNewline
write-host "'"
$count++
}
$count = 0
Write-Warning "Palettes Put this in your configuration.yaml"
write-host "shell_command:"
foreach ($item in $palettes){
write-host " set_palette_to_" -NoNewline
write-host "$count" -NoNewline
write-host ': ' -NoNewline
write-host "'curl "-NoNewline
write-host '"' -NoNewline
write-host "http://$wledip/win&FP=$count" -NoNewline
write-host '"' -NoNewline
write-host "'"
$count++
}
Write-Warning "FX Put this in your configuration.yaml"
$count = 0
write-host "input_boolean:"
foreach ($item in $effects){
$lower = $item.ToLower()
$locationlower = $location.ToLower()
$lower = $lower -replace " ","_"
Write-Host " $locationlower" -NoNewline
Write-Host "_" -NoNewline
Write-Host "$lower" -NoNewline
Write-Host "_effect" -NoNewline
Write-Host ":"
Write-Host " name: $location $item Effect"
$count++
}
Write-Warning "Palettes Put this in your configuration.yaml"
$count = 0
write-host "input_boolean:"
foreach ($item in $palettes){
$lower = $item.ToLower()
$locationlower = $location.ToLower()
$lower = $lower -replace " ","_"
Write-Host " $locationlower" -NoNewline
Write-Host "_" -NoNewline
Write-Host "$lower" -NoNewline
Write-Host "_palette" -NoNewline
Write-Host ":"
Write-Host " name: $location $item Palette"
$count++
}
Write-Warning "FX Put this in your automation.yaml"
$count = 0
foreach ($item in $effects){
$value = ([string]$count).PadLeft(3,'0')
Write-Host "- id: '9999999999$value'"
$lower = $item.ToLower()
$lower = $lower -replace " ","_"
write-host " alias: $lower"
write-host " description: ''"
write-host " trigger:"
$var = "$locationlower" + "_" + $lower + "_effect"
write-host " - entity_id: input_boolean.$var"
write-host " from: 'off'"
write-host " platform: state"
write-host " to: 'on'"
write-host " condition: []"
write-host " action:"
Write-Host " - data: {}"
write-host " service: shell_command.set_fx_to_$count"
write-host " - delay: 00:00:10"
Write-Host " - data: {}"
write-host " entity_id: input_boolean.$var"
write-host " service: input_boolean.turn_off"
$count++
}
Write-Warning "Palette Put this in your automation.yaml"
$count = 0
foreach ($item in $palettes){
$value = ([string]$count).PadLeft(3,'0')
Write-Host "- id: '9999999990$value'"
$lower = $item.ToLower()
$lower = $lower -replace " ","_"
write-host " alias: $lower"
write-host " description: ''"
write-host " trigger:"
$var = "$locationlower" + "_" + $lower + "_palette"
write-host " - entity_id: input_boolean.$var"
write-host " from: 'off'"
write-host " platform: state"
write-host " to: 'on'"
write-host " condition: []"
write-host " action:"
Write-Host " - data: {}"
write-host " service: shell_command.set_palette_to_$count"
write-host " - delay: 00:00:10"
Write-Host " - data: {}"
write-host " entity_id: input_boolean.$var"
write-host " service: input_boolean.turn_off"
$count++
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment