Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Integrating with Home Assistant #57

Open
DjordjeMandic opened this issue Jun 10, 2023 · 18 comments
Open

Integrating with Home Assistant #57

DjordjeMandic opened this issue Jun 10, 2023 · 18 comments

Comments

@DjordjeMandic
Copy link

Just a suggestion, when its already on the network mdns discovery should be implemented and home asstiant integration made for it.

@rajkoc
Copy link

rajkoc commented Jan 3, 2024

+1

2 similar comments
@neorrk
Copy link

neorrk commented Jan 18, 2024

+1

@Polimac
Copy link

Polimac commented Jan 26, 2024

+1

@psyhomb
Copy link

psyhomb commented Mar 10, 2024

You could also use existing RESTful integration if you want to add PM sensors to Home Assistant.

Example:

sensor:
  - name: Klimerko PM2.5
    unique_id: klimerko_pm2_5
    platform: rest
    resource: https://api.allthingstalk.io/asset/<ASSET_ID>
    headers:
      Authorization: !secret att_maker_api_token
      Content-Type: application/json
    device_class: pm25
    unit_of_measurement: µg/m³
    icon: mdi:molecule
    json_attributes_path: "$.state"
    json_attributes:
      - at
    value_template: "{{ value_json.state.value }}"

@rajkoc
Copy link

rajkoc commented Mar 11, 2024

Has it worked for anyone?

@psyhomb
Copy link

psyhomb commented Mar 11, 2024

It is working for me. 🙂
Screenshot 2024-03-11 at 12 54 23

@rajkoc
Copy link

rajkoc commented Mar 11, 2024

Solved, it works. In the authorization line, add Bearer and then token.

@psyhomb
Copy link

psyhomb commented Mar 11, 2024

Solved, it works. In the authorization line, add Bearer and then token.

In my case Bearer is part of the secret.

config/secrets.yaml

att_maker_api_token: "Bearer maker:<TOKEN>"

@rajkoc you should always tend to store secrets in secrets.yaml file.

@psyhomb
Copy link

psyhomb commented Mar 13, 2024

I have also created a more comprehensive configuration that use RESTful instead of RESTful Sensor integration.
This configuration will allow you to create and collect data from all Klimerko relevant sensors (PM1, PM2.5, PM10, Temperature, Humidity and Atmospheric Pressure) all in one API call.

You only need to replace <DEVICE_ID> with real value and to update secret (API token) per this post above. ⬆️

config/configuration.yaml

rest:
  # Klimerko
  - resource: https://api.allthingstalk.io/device/<DEVICE_ID>
    method: GET
    headers:
      Authorization: !secret att_maker_api_token
      Content-Type: application/json
    scan_interval: 60
    sensor:
      # PM1 sensor
      - name: Klimerko PM1
        unique_id: klimerko_pm1
        device_class: pm1
        unit_of_measurement: "µg/m³"
        icon: mdi:molecule
        json_attributes_path: "$.assets[?(@.name=='pm1')].state"
        json_attributes:
          - at
        value_template: |
          {% set sensor = value_json.assets | selectattr("name", "eq", "pm1") | first | default %}
          {{- sensor.state.value }}
      # PM2.5 sensor
      - name: Klimerko PM2.5
        unique_id: klimerko_pm2_5
        device_class: pm25
        unit_of_measurement: "µg/m³"
        icon: mdi:molecule
        json_attributes_path: "$.assets[?(@.name=='pm2-5')].state"
        json_attributes:
          - at
        value_template: |
          {% set sensor = value_json.assets | selectattr("name", "eq", "pm2-5") | first | default %}
          {{- sensor.state.value }}
      # PM10 sensor
      - name: Klimerko PM10
        unique_id: klimerko_pm10
        device_class: pm10
        unit_of_measurement: "µg/m³"
        icon: mdi:molecule
        json_attributes_path: "$.assets[?(@.name=='pm10')].state"
        json_attributes:
          - at
        value_template: |
          {% set sensor = value_json.assets | selectattr("name", "eq", "pm10") | first | default %}
          {{- sensor.state.value }}
      # Temperature sensor
      - name: Klimerko Temperature
        unique_id: klimerko_temperature
        device_class: temperature
        unit_of_measurement: "°C"
        icon: mdi:thermometer
        json_attributes_path: "$.assets[?(@.name=='temperature')].state"
        json_attributes:
          - at
        value_template: |
          {% set sensor = value_json.assets | selectattr("name", "eq", "temperature") | first | default %}
          {{- sensor.state.value }}
      # Humidity sensor
      - name: Klimerko Humidity
        unique_id: klimerko_humidity
        device_class: humidity
        unit_of_measurement: "%"
        icon: mdi:water-percent
        json_attributes_path: "$.assets[?(@.name=='humidity')].state"
        json_attributes:
          - at
        value_template: |
          {% set sensor = value_json.assets | selectattr("name", "eq", "humidity") | first | default %}
          {{- sensor.state.value }}
      # Atmospheric Pressure sensor
      - name: Klimerko Atmospheric Pressure
        unique_id: klimerko_atmospheric_pressure
        device_class: atmospheric_pressure
        unit_of_measurement: "mbar"
        icon: mdi:gauge
        json_attributes_path: "$.assets[?(@.name=='pressure')].state"
        json_attributes:
          - at
        value_template: |
          {% set sensor = value_json.assets | selectattr("name", "eq", "pressure") | first | default %}
          {{- sensor.state.value }}

@rajkoc
Copy link

rajkoc commented Mar 13, 2024

Thank you very much Miloš. Works great!

@DjordjeMandic
Copy link
Author

This works fine when it has internet access. It's still not a solution to the problem.

IMO Klimerko should have local integration with home assistant, whole point of smart home is that it works without internet access too.

@rajkoc
Copy link

rajkoc commented Mar 13, 2024

So isn't the point of sharing with the community?

@psyhomb
Copy link

psyhomb commented Mar 13, 2024

This works fine when it has internet access. It's still not a solution to the problem.

IMO Klimerko should have local integration with home assistant, whole point of smart home is that it works without internet access too.

@DjordjeMandic I couldn't agree more, still at this very moment this is all we got. 😞

Also Klimerko firmware is using pub/sub model (MQTT protocol), thus sensor data are published to public broker's endpoint, so one way on how you can generate local data w/o Internet access is by provisioning a local broker (e.g. Mosquitto + MQTT Sensor) and by modifying default broker endpoint to use local broker address where sensor and diagnostic data will be published.
I know, this way you are losing public endpoint and you still don't get some form of local API but this is just another proposal that you can implement in almost no time.

@DjordjeMandic
Copy link
Author

So isn't the point of sharing with the community?

It is, my intention was never to move it to local only. My intention is to have it do its job like it is now and besides that publish data to HA also.

My idea was to expose sensors to HA directly via HA API or use one more MQTT connection.

If anyone is willing to contribute we can implement the following:

  • MDNS local discovery (useful for HA integration)
  • Local REST API for direct connections (useful for HA integration)
  • One more MQTT connection server where HA is connected which impelments MQTT Discovery to expose sensors

Exposed stuff would include:

  • All sensor data which is already published
  • Current WiFi status (more detailed)

@psyhomb
Copy link

psyhomb commented Mar 14, 2024

One addition this approach provides is you can basically add any device that is registered and shared on the AllThingsTalk platform to HomeAssistant, not only devices that you own.

You just need to pick a shared <DEVICE_ID> from selected ground and use Ground Token instead of Device Token (personal).
2024-03-14_21-58

@psyhomb
Copy link

psyhomb commented Mar 14, 2024

So isn't the point of sharing with the community?

It is, my intention was never to move it to local only. My intention is to have it do its job like it is now and besides that publish data to HA also.

My idea was to expose sensors to HA directly via HA API or use one more MQTT connection.

If anyone is willing to contribute we can implement the following:

* MDNS local discovery (useful for HA integration)

* Local REST API for direct connections (useful for HA integration)

* One more MQTT connection server where HA is connected which impelments MQTT Discovery to expose sensors

Exposed stuff would include:

* All sensor data which is already published

* Current WiFi status (more detailed)

It would be great to have all these features implemented, the only concern I have, not saying it's justifiable, is that I don't know if this hardware (ESP8266 board) has sufficient amount of resources to support all that and how well and reliable it will work.
This is more of a question then concern, because I really don't have extended knowledge nor experience with this hardware.

@DjordjeMandic
Copy link
Author

So isn't the point of sharing with the community?

It is, my intention was never to move it to local only. My intention is to have it do its job like it is now and besides that publish data to HA also.

My idea was to expose sensors to HA directly via HA API or use one more MQTT connection.

If anyone is willing to contribute we can implement the following:

* MDNS local discovery (useful for HA integration)

* Local REST API for direct connections (useful for HA integration)

* One more MQTT connection server where HA is connected which impelments MQTT Discovery to expose sensors

Exposed stuff would include:

* All sensor data which is already published

* Current WiFi status (more detailed)

It would be great to have all these features implemented, the only concern I have, not saying it's justifiable, is that I don't know if this hardware (ESP8266 board) has sufficient amount of resources to support all that and how well and reliable it will work.
This is more of a question then concern, because I really don't have extended knowledge nor experience with this hardware.

RAM is limit here. ArduinoJson will be biggest issue but it all can be managed with proper memory allocation and code layout to prevent fragmentation as much as possible.

Rest can be managed with freertos (should have been from the start imo when there is multiple services running).

@psyhomb
Copy link

psyhomb commented Mar 15, 2024

@DjordjeMandic thank you for detailed explanation.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants