byronward
(Byron Ward)
January 26, 2025, 8:38pm
1
Hello clever people.
I’ve got a sound system where I need to know if its in ‘line-in’ mode. I cant get it to work… I can get the status using a RESTful command which returns the following -
content: >-
{"type":"0","ch":"0","mode":"40","loop":"0","eq":"0","status":"play","curpos":"26000","offset_pts":"0","totlen":"235000","Title":"556E6B6E6F776E","Artist":"556E6B6E6F776E","Album":"556E6B6E6F776E","alarmflag":"0","plicount":"0","plicurr":"0","vol":"71","mute":"0"}
status: 200
So I’ve making a sensor as follows -
sensor:
- platform: rest
name: Courtyard Mode
icon: mdi:guitar-acoustic
resource: http://192.168.1.123/httpapi.asp?command=getPlayerStatus
method: get
value_template: >
{% if value_json.content = "mode":"40" %}
line-in
{% else %}
unknown
{% endif %}
Does anyone know what I’ve got wrong?
CHANGE:
{% if value_json.mode == “40” %}
byronward
(Byron Ward)
January 26, 2025, 8:53pm
3
Thanks but its still not having it… just telling me ‘invalid config’
rest:
resource: http://192.168.1.123/httpapi.asp?command=getPlayerStatus
method: GET
scan_interval: 60
sensor:
- name: "Courtyard Mode"
icon: mdi:guitar-acoustic
value_template: >
{% if value_json.mode == '40' %}
line-in
{% else %}
unknown
{% endif %}
byronward
(Byron Ward)
January 26, 2025, 9:08pm
6
You absolute legend. I’ve been messing about with this for hours. Should have asked on here earlier.
Works perfectly
Thanks
I solved it in 30 seconds by asking ChatGPT,
I copied the json and {% if value_json.content = “mode”:“40” %} and that’s it
byronward
(Byron Ward)
January 26, 2025, 9:20pm
8
I’ve tried Chat GPT in the past for things like this and it got it wrong… but that was a couple of years ago so will give it a go next time