MelleD
March 14, 2023, 7:43am
1
Hello,
I am currently trying to trigger several sensors with the RESTful. However, the sensors are not displayed for the entities.
- resource: !secret bwt_url
scan_interval: 3600
headers:
content-type: "application/json"
ApiKey: !secret bwt_token
sensor:
- unique_id: bwt_state_title
value_template: "{{ value_json.stateTitle }}"
name: "State-Titel"
- unique_id: bwt_display_name
value_template: "{{ value_json.displayName }}"
name: "Displayname"
However, if I use json attributes, a sensor.bwt perla is created with all JSON attribute values.
- resource: !secret bwt_url
scan_interval: 3600
headers:
content-type: "application/json"
ApiKey: !secret bwt_token
sensor:
- name: "BWT Perla"
unique_id: bwt_perla
value_template: "OK"
json_attributes:
- displayName
- stateTitle
What am I doing wrong? How exactly do I read out the individual attributes?
tom_l
March 14, 2023, 7:52am
2
Your indentation is not correct. Iâm surprised the second example worked as that is wrong too. Should be:
- resource: !secret bwt_url
scan_interval: 3600
headers:
content-type: "application/json"
ApiKey: !secret bwt_token
sensor:
- unique_id: bwt_state_title
value_template: "{{ value_json.stateTitle }}"
name: "State-Titel"
- unique_id: bwt_display_name
value_template: "{{ value_json.displayName }}"
name: "Displayname"
MelleD
March 14, 2023, 7:54am
3
Thanks for the quick answer. This a copy paste error. The indentation is correct
Here the direct picture of the config. Do you see a problem here?
EdwardTFN
(Edward Firmo)
March 14, 2023, 7:59am
4
Just to isolate the problem, does this work?
- resource: !secret bwt_url
scan_interval: 3600
headers:
content-type: "application/json"
ApiKey: !secret bwt_token
sensor:
- unique_id: bwt_state_title
value_template: "OK"
json_attributes:
- stateTitle
name: "State-Titel"
- unique_id: bwt_display_name
value_template: "OK"
json_attributes:
- displayName
name: "Displayname"
Have you looked at your logs for any error message?
What do you mean by that? Are the sensors created but with no values or you donât even have the sensors?
Any chance one of those values are bigger than 255 chars?
MelleD
March 14, 2023, 8:03am
5
Nope same issue
No error message in the logs
No the sensors are not created
Nope
Maybe i need resource_template instead auf resource, but i think this is just for the url, correct? There is no template value
EdwardTFN
(Edward Firmo)
March 14, 2023, 8:09am
6
What if you remove the unique_id
?
Forget that⌠unique_id
should be supported.
EdwardTFN
(Edward Firmo)
March 14, 2023, 8:18am
7
Try a debug:
logger:
logs:
homeassistant.components.rest.sensor: debug
MelleD
March 14, 2023, 8:39am
8
@EdwardTFN here is the log
2023-03-14 09:32:27.892 DEBUG (MainThread) [homeassistant.components.rest.data] Updating from https://bwt-real-smarthome-backend.azurewebsites.net/api/Perla/xxxx
2023-03-14 09:56:18.802 DEBUG (MainThread) [homeassistant.components.rest.sensor] Data fetched from resource: {"displayName":"BWT Perla Home","stateTitle":"Alles OK!","stateBody":"Ihre Perlwasseranlage läuft einwandfrei.","deviceState":"NotSet","lastTimeDataReceived":"2023-03-14T08:54:15.04+00:00","remainingAmountOfResourcePercent":40,"refillResourceInDays":39,"isHolidayModeActive":false,"scheduledHolidayModeStart":null,"firmwareVersion":2.0012,"waterTreatedTotal":367000}
I have the feeling that the unique ids are not taken, but the name is used.
MelleD
March 14, 2023, 11:06am
9
So i removed this unique_id
. Sensor are created now. Can i changed this friendly_name?
If i use it into the sensor i get an yaml error is not supported.
EdwardTFN
(Edward Firmo)
March 14, 2023, 12:02pm
10
Friendly name is defined by the name
key on your sensor settings. You can change that.
What you donât have control without a unique_id
is to change the entity_id
(and other settings), which in this case will be the name with all lower cases and replaces non-valid chars by â_â.
Letâs say you set your sensors like this:
- resource: !secret bwt_url
scan_interval: 3600
headers:
content-type: "application/json"
ApiKey: !secret bwt_token
sensor:
- name: "Water consumption - State title"
value_template: "{{ value_json.stateTitle }}"
- name: "Water consumption - Display name"
value_template: "{{ value_json.displayName }}"
The system will create:
sensor.water_consumption_state_title
, with friendly_name
: Water consumption - State title
sensor.water_consumption_display_name
, with friendly_name
: Water consumption - Display name
.
MelleD
March 14, 2023, 12:07pm
11
As I said, if I set the unique-id, it doesnât work (maybe a bug?)
I would not prefer to have âBWTâ as a prefix everywhere in the name. But already in the sensor id this is useful like in the picture
EdwardTFN
(Edward Firmo)
March 14, 2023, 12:12pm
12
As I understood from the documentation, unique_id
should be supported, so looks like a bug.
And unfortunately without a unique_id
your entity_id
and friendly_name
are necessarily connected.
1 Like
MelleD
March 14, 2023, 12:15pm
13
Jip understand. Then i will change the friendly_name direct in the frontend as workaround.
This works:
Should I open a bug report, maybe link to this post?