Robonect module in Husqavarna Automower via mqtt vacuum

This is possible in defining e.g. a template vacuum. But I don’t like this, because of some limitations. And this one is then not connected to the device created above, because it is not possible to link yaml-entities to devices. Unfortunately.

  - platform: template
    vacuums:
      mahroboter_husqvarna_330x:
        friendly_name: "Mähroboter Husqvarna 330x"
        unique_id: unique_id_mahroboter_husqvarna_330x
        value_template: |
          {% if is_state("sensor.mahroboter_status_raw", "0") %}
            idle
          {% elif is_state("sensor.mahroboter_status_raw", "1") %}
            docked
          {% elif is_state("sensor.mahroboter_status_raw", "2") %}
            cleaning
          {% elif is_state("sensor.mahroboter_status_raw", "3") %}
            returning
          {% elif is_state("sensor.mahroboter_status_raw", "4") %}
            docked
          {% elif is_state("sensor.mahroboter_status_raw", "5") %}
            cleaning
          {% elif is_state("sensor.mahroboter_status_raw", "7") %}
            error
          {% elif is_state("sensor.mahroboter_status_raw", "8") %}
            error
          {% elif is_state("sensor.mahroboter_status_raw", "16") %}
            docked
          {% elif is_state("sensor.mahroboter_status_raw", "17") %}
            docked
          {% elif is_state("sensor.mahroboter_status_raw", "18") %}
            idle
          {% else %}
            error
          {% endif %}
        battery_level_template: "{{ states('sensor.mahroboter_batterie')|int(default=0) }}"
        start:
          service: script.rasenmahersteuerung_robonect
          data:
            message: start
        stop:
          service: script.rasenmahersteuerung_robonect
          data:
            message: stop
        return_to_base:
          service: script.rasenmahersteuerung_robonect
          data:
            message: eod
        locate:
          service: script.rasenmahersteuerung_robonect
          data:
            message: auto
        attribute_templates:
          substatus: "{{ states('sensor.mahroboter_substatus_raw') }}: {{ states('sensor.mahroboter_substatus_plain') }}"
          status: "{{ states('sensor.mahroboter_status_raw') }}: {{ states('sensor.mahroboter_status_plain') }}"

Thanks for that script, @arganto . It is such a nice way to integrate the mower into HA.
Is there a way to get the plain mode from the robonect? Currently in the script there is only the raw mode which gives me eg 2 for the (german) mode ‘Schäft’.

I’m further looking for a good way to control two things:

  1. I would like to be able to set the mower mode
  2. I would like to send an adhoc mowing job to my mower like in the robonect UI. Does anyone have an idea, how to to this from the HA UI? First step could be to send a fix job starting from now for 1 hour. Second step could be, to caonfigure an individuel input for the duration of the job starting by now.

You have to define template sensors, e.g.

  - sensor:
      - name: Mähroboter Modus lesbar
        unique_id: unique_id_mahroboter_modus_lesbar
        state: >
          {% if is_state("sensor.mahroboter_modus_raw", "0") %}
            Automatik
          {% elif is_state("sensor.mahroboter_modus_raw", "1") %}
            Manuell
          {% elif is_state("sensor.mahroboter_modus_raw", "2") %}
            Home
          {% elif is_state("sensor.mahroboter_modus_raw", "3") %}
            Demo
          {% else %}
            Versuche herauszufinden was {{ states("sensor.mahroboter_modus_raw") }} bedeutet
          {% endif %}
        icon: mdi:state-machine

  - sensor:
      - name: Mähroboter Status lesbar
        unique_id: unique_id_mahroboter_status_lesbar
        state: >
          {% if is_state("sensor.mahroboter_status_raw", "0") %}
            Erkenne Status
          {% elif is_state("sensor.mahroboter_status_raw", "1") %}
            Parkt
          {% elif is_state("sensor.mahroboter_status_raw", "2") %}
            Mäht
          {% elif is_state("sensor.mahroboter_status_raw", "3") %}
            Fährt heim
          {% elif is_state("sensor.mahroboter_status_raw", "4") %}
            Lädt
          {% elif is_state("sensor.mahroboter_status_raw", "5") %}
            Sucht
          {% elif is_state("sensor.mahroboter_status_raw", "7") %}
            Fehler
          {% elif is_state("sensor.mahroboter_status_raw", "8") %}
            Schleifensignal verloren
          {% elif is_state("sensor.mahroboter_status_raw", "16") %}
            Aus
          {% elif is_state("sensor.mahroboter_status_raw", "17") %}
            Schläft
          {% elif is_state("sensor.mahroboter_status_raw", "18") %}
            Wartet_auf_Garagentor
          {% else %}
            Versuche herauszufinden was {{ states("sensor.mahroboter_status_raw") }} bedeutet
          {% endif %}
        icon: mdi:list-status
1 Like

For ad-hoc start, I have defined a rest-sensor

rest_command:
  start_husqvarna_330x5:
    url: "http://xxx.xxx.xxx.xxx/xml?cmd=mode&mode=job&duration={{ duration }}&remotestart={{ remotestart }}&after=auto"
    method: POST
    username: !secret robonect_username
    password: !secret robonect_password

And the call it vias this service with parameters, like last call here. In this whole scipts you can find further calls and topics as well:

alias: Rasenmähersteuerung Robonect
sequence:
  - choose:
      - conditions:
          - condition: template
            value_template: "{{ message == 'start' }}"
        sequence:
          - service: mqtt.publish
            data:
              topic: automower/control
              payload: start
      - conditions:
          - condition: template
            value_template: "{{ message == 'stop' }}"
        sequence:
          - service: mqtt.publish
            data:
              topic: automower/control
              payload: stop
      - conditions:
          - condition: template
            value_template: "{{ message == 'home' }}"
        sequence:
          - service: input_select.select_option
            target:
              entity_id: input_select.mahroboter_gesetzter_modus
            data:
              option: Dauerparken
          - service: mqtt.publish
            data:
              topic: automower/control/mode
              payload: home
      - conditions:
          - condition: template
            value_template: "{{ message == 'eoj' }}"
        sequence:
          - service: input_select.select_option
            target:
              entity_id: input_select.mahroboter_gesetzter_modus
            data:
              option: Jobende
          - service: mqtt.publish
            data:
              topic: automower/control/mode
              payload: home
          - wait_for_trigger:
              - platform: state
                entity_id: sensor.mahroboter_status_raw
                to: "4"
                for:
                  hours: 0
                  minutes: 0
                  seconds: 5
                enabled: true
              - platform: state
                entity_id: sensor.mahroboter_status_raw
                to: "17"
                for:
                  hours: 0
                  minutes: 0
                  seconds: 5
                enabled: true
            enabled: false
            continue_on_timeout: false
          - wait_template: |-
              {{ states("sensor.mahroboter_nachster_start_datum") >
              strptime(states("sensor.date_time"), "%Y-%m-%d,
              %H:%M").date()|string
                 or (states("sensor.mahroboter_nachster_start_uhrzeit") != "00:00:00"
                     and as_local(strptime(states("sensor.date_time"), "%Y-%m-%d, %H:%M"))+timedelta(hours = 0, minutes = 30)
                         > as_datetime(states("sensor.mahroboter_nachster_start_datum")+"T"+states("sensor.mahroboter_nachster_start_uhrzeit")+"+02:00")
                    )
              }}
            continue_on_timeout: false
            enabled: false
          - delay:
              hours: 3
              minutes: 0
              seconds: 0
              milliseconds: 0
          - service: input_select.select_option
            target:
              entity_id: input_select.mahroboter_gesetzter_modus
            data:
              option: Automatik
          - service: mqtt.publish
            data:
              topic: automower/control/mode
              payload: auto
      - conditions:
          - condition: template
            value_template: "{{ message == 'eod' }}"
        sequence:
          - service: input_select.select_option
            target:
              entity_id: input_select.mahroboter_gesetzter_modus
            data:
              option: Tagesende
          - service: mqtt.publish
            data:
              topic: automower/control/mode
              payload: eod
      - conditions:
          - condition: template
            value_template: "{{ message == 'auto' }}"
        sequence:
          - service: input_select.select_option
            target:
              entity_id: input_select.mahroboter_gesetzter_modus
            data:
              option: Automatik
          - service: mqtt.publish
            data:
              topic: automower/control/mode
              payload: auto
      - conditions:
          - condition: template
            value_template: "{{ message == 'job' }}"
        sequence:
          - service: rest_command.start_husqvarna_330x5
            data:
              remotestart: "{{ remotestart }}"
              duration: "{{ duration }}"
mode: restart
icon: mdi:robot-mower

and inside UI I call this script via service-calls, like

                  tap_action:
                    action: call-service
                    service: script.rasenmahersteuerung_robonect
                    service_data:
                      message: eoj

or

        tap_action:
          action: |
            [[[
              if (states["sensor.mahroboter_status_raw"].state == "100"
                || states["sensor.mahroboter_status_raw"].state == "4"
                || states["sensor.mahroboter_status_raw"].state == "16"
                || states["sensor.mahroboter_status_raw"].state == "17"
              )
                return "call-service";
              else
                return "none";
            ]]]
          service: script.rasenmahersteuerung_robonect
          service_data:
            message: job
            remotestart: '4'
            duration: 90
          haptic: success
1 Like

OK, but the new sensor will not be connected to the MQTT Device, right?
The readable Status comes aout of the mqtt topic “/mower/status/plain”, so that a teamplate sensor should not be necessary.

Found here a thread where the possible controls via mqtt are descriped. Will try to use them.

Right. Unfortunately, not.

Regarding the services: Yes, but you can not use mqtt for everything. I used it in the script above, where it is possible. Just double-check. In other cases, you have to use the rest call, like the “Fernstart” and Duration.

The plain-Status is not as you want to have, because there are to many (with e.g. added meters in text in way to start and home station, etc.). You will see. :wink: Because of that I defined my own in addition.

BTW The above calls come in my case from an own card build with stacks and button-cards. Yes it is in style of an available vacuum-card, but as this was not able to do, what I want, I created this own one from scratch. Including the picture, which is of course moving, if mower is moving. :joy:

image

The 1, 2, 3 ar starting ad-hoc at different starting positions. Start and Stop are clear and Home is setting the status in another popup

image

But you can see, that the execution for all of them is bundled in the script above.

2 Likes

That looks rearly great! This is, what I want to reach :wink:
But step by step …
Where did you cnfigure your Sensor with the rest_command? I can’t find the right place or format to do it.
The Script is in place but needs the additional input Helper. Thats my next step.

It has to be defined in the configuration.yaml

Thats a part of my configuration.yaml

automation: !include automations.yaml
script: !include scripts.yaml
scene: !include scenes.yaml
sensor: !include_dir_merge_list sensor/
binary_sensor: !include_dir_merge_list sensor_binary/
template: !include template.yaml

In the folder “sensor” I’ve got severel *.yaml files. For yiur Rest-Sensor i created a new file called rest.yaml in my sensor folder.

- rest_command:
  start_gardena_r40li:
    url: "http://192.168.178.33/xml?cmd=mode&mode=job&duration={{ duration }}&remotestart={{ remotestart }}&after=auto"
    method: POST
    username: !secret robonect_username
    password: !secret robonect_password

The configartion check gives me this error message:

Invalid config for [sensor]: required key not provided @ data['platform']. Got None

Where is my mistake?

It’s not a sensor. It is a rest_command. So it needs to be in the root as sensor: group: switch: etc. And don’t invent different indents. My example is correct.

Would you Share youre UI yaml Code?
With youre help I get the control of my mower working. Now it has to become a nicer layout. As you can assume, I‘m new to Home Assistant.

1 Like

Here is my first attempt for a simple mower card. For sure, it will neet some more styling, designing and some dynamic content. But for the first try an my current knowlege it’s ok.
The Buttons on the bottom uses the skript from @arganto. That works great. Thanks al lot!

image

type: custom:stack-in-card
title: Mähroboter
mode: vertical
cards:
  - type: horizontal-stack
    cards:
      - type: entity
        entity: sensor.mahroboter_status_lesbar
        name: Status
        state_color: false
        icon: none
      - type: entity
        entity: sensor.mahroboter_modus_lesbar
        name: Modus
        state_color: false
        icon: none
      - type: entity
        entity: sensor.mahroboter_batterie
        name: Batterie
        state_color: false
        icon: none
  - type: horizontal-stack
    cards:
      - type: entity
        entity: sensor.mahroboter_messerqualitat
        name: Messer
      - type: entity
        entity: sensor.mahroboter_im_aktuellen_status
        name: Status seit
        unit: min
      - type: entity
        entity: sensor.mahroboter_betriebsstunden
        name: Betrieb
        unit: ' h'
        state_color: false
  - type: horizontal-stack
    cards:
      - type: custom:button-card
        icon: mdi:home
        tap_action:
          action: call-service
          service: script.rasenmaehersteuerung_robonect
          service_data:
            message: home
      - type: custom:button-card
        icon: mdi:play
        tap_action:
          action: call-service
          service: script.rasenmaehersteuerung_robonect
          service_data:
            message: start
      - type: custom:button-card
        icon: mdi:stop
        tap_action:
          action: call-service
          service: script.rasenmaehersteuerung_robonect
          service_data:
            message: stop
      - type: custom:button-card
        icon: mdi:pause
        tap_action:
          action: call-service
          service: script.rasenmaehersteuerung_robonect
          service_data:
            message: eod
      - type: custom:button-card
        icon: mdi:clock-start
        tap_action:
          action: call-service
          service: script.rasenmaehersteuerung_robonect
          service_data:
            message: job
            duration: 200
            remotestart: 0

Why you don’t make an HACS integration? (Would be great :slight_smile: )

1 Like

Anyone know if it is possible and what to publish to MQTT to do a remote start?

AFAIK not possible. See REST API examples above instead.

My Robonect card:

1 Like

automower/control

and you have start & stop as payload possibilities

I’ll try to find some time this week and create an integration for HA :slight_smile:

Have created a discord server where I will push updates and where things can be easily discussed

image

1 Like

But no start with starting point, duration, etc. Think that was the question and was the reason for my reply.

1 Like