I’m trying to automate on the change of a state. From any state to the state below but I can’t get it to work. I’m guessing that it’s a problem of escaping characters?
HTTP/1.1 200 OK Content-Type: application/json Content-Length: 110 Connection: keep-alive {"result":[{"uri":"extInput:cec?type=recorder&port=3&logicalAddr=1","source":"","title":"CoreELEC"}],"id":103}
can you provide a bit more information please. Is everything you posted the full state, or is it the json only? Also, post the entity that has this information in the developer tools state page. That will tell me where the information is.
Ok, so you’re going to run into issues with your full state being json. States are limited to 255 characters, and your state will be chopped off while producing an error.
Please post the configuration for sensor.test. We can adjust it to avoid that situation.
This is the sensor below:
sensor:
- platform: command_line
name: test
command: curl -i -H 'X-Auth-PSK:password' -d '{"method":"getPlayingContentInfo","id":103,"params":[],"version":"1.0"}' http://192.168.0.251/sony/avContent
scan_interval: 1
value_template: '{{ value }}'
value_template: >
{{ value | regex_findall('"title":"([a-zA-Z0-9 ]+)"') | first | default(none) }}
Make sure you do not use a single line template. You have to use the > and put the template on the next line. I.e. Copy what I wrote, do not change it.
The state of your sensor will now be the title only.