State unknown

Hi everybody.
Enjoying HA.
Trying to make use of a REST sensor.
But it does not work :frowning: Can anyone guide me where I’m wrong?
I’ve got the following:

  • platform: rest
    name: JSON Climaxalarm
    resource: ‘http://user:[email protected]/action/panelCondGet
    json_attributes:
    • mode_a1
      value_template: ‘{{ value_json.climaxalarm }}’
  • platform: template
    sensors:
    climaxalarm_status:
    friendly_name: ‘Mode’
    value_template: ‘{{ states.sensor.json_climaxalarm.attributes[“updates”][“mode_a1”] }}’

If I do a cURL of the url I get this:

{
“updates” : {
“mode_a1” : “Disarm”,
“mode_a2” : “Disarm”,
“mode_a3” : “Disarm”,
“mode_a4” : “Disarm”,
“mode_a5” : “Disarm”,
“battery_ok” : “1”,
“battery” : “Normal”,
“tamper_ok” : “1”,
“tamper” : “N/A”,
“interference_ok” : “1”,
“interference” : “Normal”,
“ac_activation_ok” : “1”,
“ac_activation” : “Normal”,
“sys_in_inst”: “System in maintenance”,
“rssi” : “1”,
“sig_gsm_ok” : “1”,
“sig_gsm” : “N/A”
}
}

But the output of the climaxalarm_status is ‘Unknown’
Log says:

2019-07-20 15:42:12 DEBUG (MainThread) [homeassistant.core] Bus:Handling <Event state_changed[L]: entity_id=sensor.climaxalarm_status, old_state=None, new_state=<state sensor.climaxalarm_status=unknown; friendly_name=Mode @ 2019-07-20T15:42:12.891921+02:00>>
2019-07-20 15:42:13 DEBUG (SyncWorker_12) [homeassistant.components.rest.sensor] Updating from http://user:[email protected]/action/panelCondGet

Any takes on why the ‘Mode’ is ‘Unknown’?

Thanks in advance!

Please format your code. Given the way it currently appears, it’s difficult understand how you’ve configured sensor.json_climaxalarm. For example, its value_template does not have the correct indentation nor do the options for the Template Sensor.

If the URL returns the data that you posted above, why does the value_template append climaxalarm to value_json? There’s no key in the data called climaxalarm.

Thanks for the reply :slight_smile:
New to the forum - how I format the code?

Anyways - so what you are saying is that I should replace the climaxalarm with updates?

When you post unformatted code, this forum’s software pops up a message explaining it has noticed you are posting unformatted code and makes suggestions how to format it. Did you simply dismiss this pop-up message?

There’s an icon in the forum’s editing menu that looks like this: </>
It’s purpose is to format code.

The forum’s editor understands markdown formatting. The markdown way to format code is to enter three backquotes ``` on a separate line before your code and another three, on a separate line, after your code.

I don’t understand what you mean by ‘updates’.

I was referring to the fact that the value_template for sensor.json_climaxalarm, namely this one:

{{ value_json.climaxalarm }}

refers to a key in the received data called climaxalarm. However, based on the data you posted above, it has no key called climaxalarm. So either it’s a mistake to refer to this key or the data you posted isn’t what is received by the sensor.

sensor:
  # Alarm
  - platform: rest
    name: JSON Climaxalarm
    resource: 'http://user:[email protected]/action/panelCondGet'
    json_attributes:
      - mode_a1
    value_template: '{{ value_json.climaxalarm }}'
  - platform: template
    sensors:
      climaxalarm_status:
        friendly_name: 'Mode'
        value_template: '{{ states.sensor.json_climaxalarm.attributes["updates"]["mode_a1"] }}'

tried to format the text using what I interpreted from your message using the </>-button
Again:

{
  "updates" : {
    "mode_a1" : "Disarm",
    "mode_a2" : "Disarm",
    "mode_a3" : "Disarm",
    "mode_a4" : "Disarm",
    "mode_a5" : "Disarm",
    "battery_ok" : "1",
    "battery" : "Normal",
    "tamper_ok" : "1",
    "tamper" : "N/A",
    "interference_ok" : "1",
    "interference" : "Normal",
    "ac_activation_ok" : "1",
    "ac_activation" : "Normal",
    "sys_in_inst": "System in maintenance",
    "rssi" : "1",
    "sig_gsm_ok" : "1",
    "sig_gsm" : "N/A"
  }
}

In the end: how do I make it work?

Thanks in advance :+1: :smiley:

Excellent! Much easier to read now.

The question remains the same though. Why are you using this:

{{ value_json.climaxalarm }}

when there’s no climaxalarm key in the data:

{
  "updates" : {
    "mode_a1" : "Disarm",
    "mode_a2" : "Disarm",
    "mode_a3" : "Disarm",
    "mode_a4" : "Disarm",
    "mode_a5" : "Disarm",
    "battery_ok" : "1",
    "battery" : "Normal",
    "tamper_ok" : "1",
    "tamper" : "N/A",
    "interference_ok" : "1",
    "interference" : "Normal",
    "ac_activation_ok" : "1",
    "ac_activation" : "Normal",
    "sys_in_inst": "System in maintenance",
    "rssi" : "1",
    "sig_gsm_ok" : "1",
    "sig_gsm" : "N/A"
  }
}

You said that’s the data that is returned by cURL. It has no climaxalarm key in it so {{ value_json.climaxalarm }} will produce nothing.

:smiley:
So - I get that part. But what should be written instead of climaxalarm? Should I use updates?
I’m fairly new on this one, so please bear with me.

I asked you a question about something you entered in the configuration and, instead of explaining why you did it you say “I get that part”. How am I supposed to interpret that non-answer? :man_shrugging:

If you change the value_template to:

'{{ value_json.updates }}'

It will attempt to read all the data into the sensor’s state and fail. That’s because state can only hold a maximum of 255 characters and your data exceeds that.

OK, bottomline:
I want the value of mode_a1. How would I get that value?
I really appreciate the help here, but I’m struggling to interpret what you want from me?! I’m beginning to learn this templating and it seems like I’m missing something?!

I get the part about that I cannot use climaxalarm… That’s all.

sensor:
  - platform: rest
    name: JSON Climaxalarm
    resource: 'http://user:[email protected]/action/panelCondGet'
    value_template: '{{ value_json.updates.mode_a1 }}'
1 Like

Thanks :+1:
Works like a charm!

1 Like

Glad you managed to sort it. @123 is a guru in this (and many other areas).

As you are new around here, please read this, it is longish, but important :slight_smile:

1 Like