@sambuddy200471 wrote:
Hello All,
I have created a tcp server to act as a tcp sensor. The server responds with the following json string when it receives a request
{ "ch1": { "watts": "1000"},"ch2": { "watts": "2000"},"ch3": { "watts": "3000"},"total": { "watts": 6000}}
when i use the following sensor setup, the developer tools window shows a state of unknown.
name: House Power Consumption host: 192.168.150.32 port: 10000 timeout: 5 payload: "GET\n" value_template: '{{ value.total.watts }}' unit_of_measurement: Watt
but, if i hard code the response (as below) into the value template, i get the expected response of 6000
name: House Power Consumption host: 192.168.150.32 port: 10000 timeout: 5 payload: "GET\n" value_template: '{% set my_test_json = {"ch1": { "watts": "1000"},"ch2": { "watts": "2000"},"ch3": {"watts": "3000"},"total": {"watts": "6000"},}%} {{ my_test_json.total.watts }}' unit_of_measurement: Watt
having tried numerous combinations in the value template, (with no success), I think what the problem is, is that ‘value’ is treated as a string when it is received from the server BUT if i hard code the value, it is treated as a JSON object.
Having come to that conclusion, i tried to convert the string to a json object using either ‘value_json’ which returns blank or ‘value|to_json’ which returns the string BUT with every inverted comma being delimited with a slash e.g." becomes " .Can anyone see what i am doing wrong?
Thanks
Stuart
P.S. I have done a fair bit of searching on this topic and have found alot of solutions…but none of them are working in my case.
Posts: 4
Participants: 2