#Rest integration with client certificate

23 messages · Page 1 of 1 (latest)

lost dagger
#

Hi again,
I have an endpoint in public internet, which upon POST request responds with JSON containing some values I'd like to use and display in HA.
It authenticates clients with PKCS certificate though.

Is there any way, how to make this work in HA's REST integration? I'm not able to find any much documentation on this.

The endpoint is on my public server, so as a worst case scenario, I am able to rewrite that endpoint to some other authentication, but I would really like to avoid doing so, as it is used in a lot of other applications... :/

unkempt raptor
#

A potential alternative would be to look into a command_line sensor utilizing curl.

lost dagger
#

So, I created the sensor under /config/sensors/cmd/komando.yaml:

- name: "Next shift"
  platform: command_line
  command: curl -F "AdId=xxxx" -F "SapId=xxxx" -F "DeviceId=0" -F "Heslo=xxxxx" -F "ProfeseId=83112" -F "IdKalendar=xxxxxx@group.calendar.google.com" -F "SrcSystem=APS" -F "Certifikat=@cdis-cz.p12" https://xxxx.yyy/komando/save_shifts
  command_timeout: 60
  json_attributes:
    - content.next_shift.name
    - content.next_shift.startTime
    - content.next_shift.startLocation
    - content.next_shift.endTime
    - content.next_shift.endLocation
  scan_interval: 1800``` and included it like in config.yaml
```YAML
sensor: !include_dir_merge_named sensors``` 
but I'm not able to find it in the entities, nor there is any related error message in Core log.
What could I be doing wrong?
#

Also, I had other mqtt sensors included into configuration.yaml like this:

mqtt: !include_dir_merge_named sensors

and in /config/sensors there was a file called bme_living_room.yaml with content:

sensor:
  - name: "Teplota v obýváku"
    state_topic: "domov/obyvak/rpi/sensor/temperature"
    suggested_display_precision: 1
    state_class: measurement
    device_class: temperature
    unit_of_measurement: "°C"
    unique_id: "domov/obyvak/rpi/sensor/temperature"
    value_template: "{{ value_json }}"

  - name: "Vlhkost v obýváku"
    state_topic: "domov/obyvak/rpi/sensor/humidity"
    state_class: measurement
    device_class: humidity
    unit_of_measurement: "%"
    unique_id: "domov/obyvak/rpi/sensor/humidity"
    value_template: "{{ value_json }}"

  - name: "Tlak v obýváku"
    state_topic: "domov/obyvak/rpi/sensor/pressure"
    state_class: measurement
    device_class: atmospheric_pressure
    unique_id: "domov/obyvak/rpi/sensor/pressure"
    unit_of_measurement: "hPa"
    value_template: "{{ value_json }}"

which I thought I had to change to

- name: "Teplota v obýváku"
  platform: mqtt
  state_topic: "domov/obyvak/rpi/sensor/temperature"
  suggested_display_precision: 1
  state_class: measurement
  device_class: temperature
  unit_of_measurement: "°C"
  unique_id: "domov/obyvak/rpi/sensor/temperature"
  value_template: "{{ value_json }}"

- name: "Vlhkost v obýváku"
  platform: mqtt
  state_topic: "domov/obyvak/rpi/sensor/humidity"
  state_class: measurement
  device_class: humidity
  unit_of_measurement: "%"
  unique_id: "domov/obyvak/rpi/sensor/humidity"
  value_template: "{{ value_json }}"

- name: "Tlak v obýváku"
  platform: mqtt
  state_topic: "domov/obyvak/rpi/sensor/pressure"
  state_class: measurement
  device_class: atmospheric_pressure
  unique_id: "domov/obyvak/rpi/sensor/pressure"
  unit_of_measurement: "hPa"
  value_template: "{{ value_json }}"

to keep it working under sensor integration and that stopped working too 😄

#

I guess mqtt: !include_dir_merge_named and sensor: inside individual configs is not equal to sensor: !include_dir_merge_named and adding platform: mqtt?

unkempt raptor
#

Including the same directory across 2 integrations likely isn't desirable

lost dagger
#

Yeah, therefore I changed it so that the directory only contains sensor integration and added platform: mqtt directly to each sensor, that was under mqtt: ....
That should be equal or not?

unkempt raptor
#

Have you found documentation stating that it is?

#

Defining MQTT entities under their platform was removed back in 2022

#

They need to be defined under mqtt

lost dagger
#

Oh. So

mqtt:
  sensor:
    -  name: blah blah

is no more

sensor:
  - platform: mqtt
    name: blah blah
```?
unkempt raptor
#

You need to use the top method, the bottom method is not supported anymore

lost dagger
#

That'l be it 🙂

Same is for command_line integration?

unkempt raptor
lost dagger
#

thx, one last thing.
is there something like !include_dir_merge_named but only to include all yamls in directory and not subdirectories?

unkempt raptor
#

Or use the .yml extension on those you don't want to import... depending on what exactly you're looking to do

lost dagger
unkempt raptor
#

perhaps just use something like sensors/sensor for the first one

lost dagger
# unkempt raptor I'll refer you to the documentation: <https://www.home-assistant.io/integrations...

So I rewrote the sensor based on this docs, restarted HA, Command Line integration popuped in Integrations, but still no error, nor Entity shows up
configuration.yaml:

...
command_line: !include_dir_merge_named sensors/cmd

sensors/cmd/komando.yaml:

- sensor:
    name: "Další směna"
    command: curl -F "AdId=xxxx" -F "SapId=xxxx" -F "DeviceId=0" -F "Heslo=xxxx" -F "ProfeseId=83112" -F "IdKalendar=xxxx@group.calendar.google.com" -F "SrcSystem=APS" -F "Certifikat=@cdis-cz.p12" https://xxxx.yyy/komando/save_shifts
    command_timeout: 60
    json_attributes:
      - content.next_shift.name
      - content.next_shift.startTime
      - content.next_shift.startLocation
      - content.next_shift.endTime
      - content.next_shift.endLocation
    scan_interval: 1800
    value_template: "{% if value_json.content.next_shift is defined -%}Následující směna {{ value_json.content.next_shift.name }} začne {{ as_timestamp(value_json.content.next_shift.startTime) | timestamp_custom('%d. %m. %Y ve %H:%M:%S') }} v žst. {{ value_json.content.next_shift.startLocation }}.{%- else -%}V komandu není zadána žádná další směna.{%- endif %}"
unkempt raptor
#

I think you want !include_dir_merge_list named outputs a dictionary, which isn't what the command_line integration expects

lost dagger
#

so if the included file directly contains list (- something:), then I should use _list, where as if it contains names (something:) it is _named?