I’m a bit confused about what your goal is. Your dupline_a1_temperature sensor’s state is just whatever the min_dupline_a1_temperature sensor’s state is. Why do you need two sensors at all if they are the same?
You also didn’t mention which sensor (of those two) you say is updated, but with no properties. If it’s min_dupline_a1_temperature, this is exactly as expected since you didn’t provide any attributes when you created it using the REST API.
Since I don’t know what it is you’re really trying to accomplish, I’m not sure how to suggest a path forward. You could just have the one sensor that you create using the API (no need to declare it in YAML at all). Since the attributes are all static, you can include them in the json data in your VB script.
Finally, fwiw, I wouldn’t consider instantiating sensors via REST API calls to be a very mainstream usage of Home Assistant. Maybe if you describe your use case in more detail, we could suggest a more straightforward approach.
I get a lot of input from various PLCs, Dupline etc…
All values end up in a program written in visual basic, for example a temperature sensor: “termofoler_dupline_a1_temperature”
My wish is to send the values to the Home Assistant where I can present the temperature and perform some automation.
The question is how this can be done, and how I get both values and units sent to Home Assistent, I think a jason string should be sent, I just don’t know the format.
I didn’t mean to imply that it was wrong or invalid. Just that a self-professed new HA user who landed on this approach might have missed something easier or more accessible. Perhaps that’s not the case here.
I have worked quite a bit with HA, but am relatively new to YAML and Json
I have tried your suggestion unfortunately I get error “400“, I can’t see what’s wrong.
This works perfectly
Dim client As New System.Net.WebClient()
client.Headers.Add("Authorization", "Bearer " & token)
client.Headers.Add("Content-Type", "application/json")
Dim reply As String = client.UploadString(url, "POST", jsonData)
#jsonData = {"state":"18.20"}
This doesn’t work: “The remote server returned an error: (400) Bad request”
Dim client As New System.Net.WebClient()
client.Headers.Add("Authorization", "Bearer " & token)
client.Headers.Add("Content-Type", "application/json")
Dim reply As String = client.UploadString(url, "POST", jsonData)
#jsonData = {"state":"18.20","attributes":{"device_class":"temperature","icon":"mdi:thermometer","unit_of_measurement":"°C"}}
I don’t know VB though. What’s going on with the #jsonData declaration? Is it possible it’s changing the JSON object somehow or maybe doesn’t like nested objects? Also, what URL are you using? Your original post had the JSON object repeated at the end of the URL which was a bit confusing…
I have now found the error as you suggested the error occurred in VB. Many thanks for the help, without your input I wouldn’t know where to troubleshoot.
This is what I was missing in the VB code: client.Encoding = System.Text.Encoding.UTF8
Dim client As New System.Net.WebClient()
client.Encoding = System.Text.Encoding.UTF8
client.Headers.Add("Authorization", "Bearer " & token)
client.Headers.Add("Content-Type", "application/json")
Dim reply As String = client.UploadString(url, "POST", JsonData)