Home-Assistant Integration

Anleitungen und Tipps
Andreas
Beiträge: 10
Registriert: Fr 19. Mär 2021, 20:30

Home-Assistant Integration

Beitrag von Andreas »

Hallo Zusammen,

ich habe die Rest-API in den Home-Assistant integriert - ich hoffe es spart jemandem Zeit.
Alle settings sind in der "configuration.yaml" zu erledigen. Anschließend können die Werte über das Dashboard oder Automatisierungen verwendet werden.

Viele Grüße
Andreas

Code: Alles auswählen

sensor:
  # smartWB
  - platform: rest
    name: smartWB
    authentication: basic
    scan_interval: 10
    resource: http://<smartwb>/getParameters
    json_attributes_path: "$.list.[0]"
    value_template: '{{ value_json.smartwb }}'
    json_attributes:
       - "vehicleState"
       - "evseState"
       - "actualCurrent"
       - "actualPower"
       - "duration"
  - platform: template
    sensors:
      smartwb_actualcurrent:
        friendly_name: 'Actual Current'
        unit_of_measurement: "A"
        device_class: 'current'
        value_template: '{{ states.sensor.smartwb.attributes["actualCurrent"] }}'
      smartwb_actualpower:
        friendly_name: 'Actual Power'
        unit_of_measurement: "kW"
        value_template: '{{ states.sensor.smartwb.attributes["actualPower"] }}'
      smartwb_duration:
        friendly_name: 'Duration'
        unit_of_measurement: "Minutes"
        value_template: '{{ ((states.sensor.smartwb.attributes["duration"] | int / 60000 | round(1) )) }}'
      smartwb_vehiclestate:
        friendly_name: 'Vehicle State'
        value_template: >- 
          {% set mapper = ['Unknown', 'Ready', 'Detected', 'Charging'] %}
          {{ mapper[states.sensor.smartwb.attributes["vehicleState"] | int] }}

Code: Alles auswählen

binary_sensor:
  - platform: template
    sensors:
      smartwb_evsestate:
        friendly_name: 'EVSE State'
        value_template: '{{ states.sensor.smartwb.attributes["evseState"] }}'
Um den Stromwert flexibel setzen zu können habe ich einen "Helper" "'input_number.smartwbcurrent'" angelegt.

Code: Alles auswählen

rest_command:
  smartwb_activate:
    url: 'http://<smartwb>/setStatus?active=true'
    method: GET
  smartwb_deactivate:
    url: 'http://<smartwb>/setStatus?active=false'
    method: GET
  smartwb_setcurrent:
    url: "http://<smartwb>/setCurrent?current={{ states('input_number.smartwbcurrent') }}"
    method: GET

Mathias
Administrator
Beiträge: 222
Registriert: Di 12. Mai 2020, 09:12

Re: Home-Assistant Integration

Beitrag von Mathias »

Cool - danke dir Andreas! :)

Andreas
Beiträge: 10
Registriert: Fr 19. Mär 2021, 20:30

Re: Home-Assistant Integration

Beitrag von Andreas »

schaut echt gut aus - und ist kompatibel mit anderen Haushaltsbewohnern ;-)
wenn jemand Interesse hat gerne melden - es gibt noch ein bisschen was zu tunen...
2021-04-05 07_40_12-Home - Home Assistant.png
2021-04-05 07_40_12-Home - Home Assistant.png (28.8 KiB) 53374 mal betrachtet

MFelten
Beiträge: 3
Registriert: Sa 13. Jun 2020, 11:17

Re: Home-Assistant Integration

Beitrag von MFelten »

Hi Andreas,

Great work! Thank you.

Could you help me integrate this in my home assistant?
I'm new to HAS. Currently I'm using domoticz but I'm considering switching to HAS.

How do you add this integration?


Thanks you!

Andreas
Beiträge: 10
Registriert: Fr 19. Mär 2021, 20:30

Re: Home-Assistant Integration

Beitrag von Andreas »

Hey, all the code sections need to be added to the configuration.yaml file. Just replace <smartwb> with the IP or host name of your Wallbox. If done you can add ui elements just as you like.
Good luck!

Till now I'm absolutely happy with HA and many different integrations.

MFelten
Beiträge: 3
Registriert: Sa 13. Jun 2020, 11:17

Re: Home-Assistant Integration

Beitrag von MFelten »

Awesome!

I added your code and am now able to view the status of the wallbox.

Just one more question; How can I control the wallbox from HAS?
I noticed you have a slider controller for current control. And buttons for start/stop. How do I set that up?

Also, I added the "energy" parameter:

Code: Alles auswählen

      smartwb_energy:
        friendly_name: 'Energy'
        unit_of_measurement: "kWh"
        value_template: '{{ states.sensor.smartwb.attributes["energy"] }}'

Andreas
Beiträge: 10
Registriert: Fr 19. Mär 2021, 20:30

Re: Home-Assistant Integration

Beitrag von Andreas »

Sounds like you already did the most important work!

To command the smartWB you need the rest commands.
Since the first post I have added the "InterruptCp". This is needed if your car does not start charging after being connected a while without being charged.

Code: Alles auswählen

rest_command:
  smartwb_activate:
    url: 'http://smartwb/setStatus?active=true'
    method: GET
  smartwb_deactivate:
    url: 'http://smartwb/setStatus?active=false'
    method: GET
  smartwb_setcurrent:
    url: "http://smartwb/setCurrent?current={{ states('input_number.smartwbcurrent') }}"
    method: GET
  smartwb_interruptcp:
    url: "http://smartwb/interruptCp"
    method: GET
For the slider I used a helper variable 'input_number.smartwbcurrent' this is used in the UI-Element:

Code: Alles auswählen

type: entities
entities:
  - entity: input_number.smartwbcurrent
    name: Wallbox
title: Ladestrom
To really send it to the device you need the buttons - they send the rest_commands:

Code: Alles auswählen

type: grid
cards:
  - type: button
    name: Ladestrom festlegen
    tap_action:
      action: call-service
      service: rest_command.smartwb_setcurrent
      service_data: {}
      target: {}
    show_state: true
    icon: 'hass:arrow-up-down'
  - type: button
    name: Laden aktivieren
    tap_action:
      action: call-service
      service: rest_command.smartwb_activate
      service_data: {}
      target: {}
    hold_action:
      action: none
    icon: 'hass:power-plug'
  - type: button
    name: Laden deaktivieren
    tap_action:
      action: call-service
      service: rest_command.smartwb_deactivate
      service_data: {}
      target: {}
    hold_action:
      action: none
    icon: 'hass:power-plug-off'
    show_state: false
  - type: button
    name: Ladestart auslösen
    tap_action:
      action: call-service
      service: rest_command.smartwb_interruptcp
      service_data: {}
      target: {}
    hold_action:
      action: none
    icon: 'hass:restart-alert'
square: false
Sorry for having all the german artifacts in the examples - I hope you still get the point.
(if not don't mind asking)

MFelten
Beiträge: 3
Registriert: Sa 13. Jun 2020, 11:17

Re: Home-Assistant Integration

Beitrag von MFelten »

Thanks!

With your help I was able to make the control buttons.

The slider doesn't work yet.
I'm not sure where to create the helper variable with the code you supplied.

Andreas
Beiträge: 10
Registriert: Fr 19. Mär 2021, 20:30

Re: Home-Assistant Integration

Beitrag von Andreas »

you need to create the helpers via the UI: settings -> helper -> create -> type number (name as used in the configuration)

I hope that's the missing link.

riogrande75
Beiträge: 11
Registriert: Mo 13. Jul 2020, 10:50

Re: Home-Assistant Integration

Beitrag von riogrande75 »

Hallo Andreas!
Wenn ich den Code aus dem ersten Post in meine configuration.yaml einfüge und den Helper mittels UI konfiguriere, dann bekomme ich Fluten von folgender Fehlermeldung:

Code: Alles auswählen

2023-07-17 11:56:00.870 WARNING (MainThread) [homeassistant.helpers.template] Template variable warning: 'dict object' has no attribute 'smartwb' when rendering '{{ value_json.smartwb }}'
Leider funktioniert das Ladestand setzten dann auch nicht.
In Post 7 hast du dann noch etwas gepostet, bin aber als Anfänge nicht so recht in der Lage das korrekt einzubauen.

Wärst du so freundlich nochmal den gesamten Code für die Integration zu posten?

Antworten