Hi all,
I’m trying to write a powershell script to send an API POST request to home assistant to update a custom sensor I’ve created to store my meeting events for that day, however I’m having a hard time figuring out how to post an entities attributes if they contain a list of objects.
Basically I am trying to achieve something like this this:
However when I create a test object in PS I get the following result in HA:
Here is my testing PS script:
$headers = @{"Authorization"="Bearer $HAToken";}
Write-Host ("Setting Microsoft Teams meetings test")
$params = @{
"state"="Valid";
"attributes"= @{
"friendly_name"="$entityMeetingsName";
"icon"="mdi:microsoft-teams";
"meetings" = (
@{
"name"="test1";
"start_time" = "9:01";
},
@{
"name"="test2";
"start_time"="11:00";
})
}
}
$params.attributes.meetings = $params.attributes.meetings | ConvertTo-Json
$params = $params | ConvertTo-Json
Invoke-RestMethod -Uri "$HAUrl/api/states/$entityMeetings" -Method POST -Headers $headers -Body ([System.Text.Encoding]::UTF8.GetBytes($params)) -ContentType "application/json"
This is my first time attempting to use both PS and home assistant APIs so please be kind