Help with Mower and json

Hi
I have a Worx Landroid mower with wifi connection and a webserver that uses json.

Today I connect to the mover to fetch data using following python code:

def send_check():
try:
    response = requests.get(Config.get("Landroid", "Addr"), auth=(Config.get("Landroid", "User"),Config.get("Landroid", "Pin")), timeout=5)
    data = response.json()
    check_general(data)
    debug_print(data)
except requests.exceptions.Timeout:
    print("Connection timeout")
except requests.exceptions.RequestException:
    print("Connection error")

Then I publish the information to my broker:

def check_general(data):
os.system("mosquitto_pub --cafile ca.crt -h 192.168.1.32 -p 8883 -t \"landroid/battery\" -m \"" + str(data['perc_batt']) +"\"" )
os.system("mosquitto_pub --cafile ca.crt -h 192.168.1.32 -p 8883 -t \"landroid/working_hours\" -m \"" +   str(float(data['ore_movimento'])/10) +"\"" )

I know I then can create a sensor in HASS that fetches the MQTT data but couldn’t I do the json request directly in HASS?
If so, how and what are the benefits (if any)

I think a mower component would be nice in HASS but I don’t have the knowledge to code one. I am of course willing to test/debug it is someone is willing to give it a shot.

Source code that I used as a base:

Thanks

The REST sensor could be used as a base for a Worx Landroid mower platform. Support for auth would be needed.

Does your JSON response looks the same as described here?

Actually I used this script before but it stopped working after I moved to HTTPS and password.

auth is used like this: auth=(Config.get(“Landroid”, “User”) in
requests.get(Config.get(“Landroid”, “Addr”), auth=(Config.get(“Landroid”, “User”),Config.get(“Landroid”, “Pin”)), timeout=5)

My json response is like this:

{  
   "CntProg":404,
   "lingua":0,
   "ore_funz":[  
      192,
      195,
      195,
      195,
      192,
      195,
      192
   ],
   "ora_on":[  
      9,
      9,
      9,
      9,
      9,
      9,
      9
   ],
   "min_on":[  
      0,
      0,
      0,
      0,
      0,
      0,
      0
   ],
   "allarmi":[  
      0,
      0,
      1,
      0,
      0,
      0,
      0,
      0,
      0,
      0,
      0,
      0,
      0,
      0,
      0,
      0,
      0,
      0,
      0,
      0,
      0,
      0,
      0,
      0,
      0,
      0,
      0,
      0,
      0,
      0,
      0
   ],
   "settaggi":[  
      0,
      0,
      0,
      0,
      1,
      0,
      0,
      1,
      1,
      0,
      0,
      0,
      0,
      0,
      0,
      0,
      0,
      0,
      0,
      0,
      0,
      0,
      0,
      0,
      0,
      0,
      0,
      0,
      0,
      0,
      0
   ],
   "mac":[  
      0,
      35,
      167,
      72,
      146,
      130
   ],
   "time_format":1,
   "date_format":0,
   "rit_pioggia":60,
   "area":0,
   "enab_bordo":0,
   "g_sett_attuale":0,
   "g_ulti mo_bordo":0,
   "ore_movimento":8678,
   "percent_programm atore":0,
   "indice_area":9,
   "tipo_lando":8,
   "beep_hi_l ow":0,
   "gradi_ini_diritto":30,
   "perc_cor_diritto":10   3,
   "coef_angolo_retta":80,
   "scost_zero_retta":1,
   "off set_inclinometri":[  
      2072,
      2035,
      2688
   ],
   "gr_rall_inizio":80,
   "gr_rall_finale":300,
   "gr_ini_ frenatura":130,
   "perc_vel_ini_frenatura":50,
   "tempo_ frenatura":20,
   "perc_rallenta_max":50,
   "canale":0,
   "n um_ricariche_batt":5,
   "num_aree_lavoro":3,
   "Dist_are a":[  
      10,
      70,
      55,
      1
   ],
   "perc_per_area":[  
      2,
      2,
      6,
      1
   ],
   "area_in_lavoro":6,
   " ",
   "perc_batt":"58"
}

Starting with 0.30 you should be able to use the REST sensor for your mower.

thank you @fabaff seems to work!

Follow up question that maybe is more related to templates than json.

In json response “allarmi” an array is returned:
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]

an error can either be 0 or 1 and each number corresponds to an error code such as:

[‘blade_blocked’,
‘repositioning_error’,
‘outside_wire’,
‘blade_blocked’,
‘outside_wire’,
‘mower_tilted’,
‘error’,
‘error’,
‘error’,
‘collision_sensor_blocked’,
‘mower_tilted’,
‘charge_error’,
‘battery_error’]

How can I translate the numbers in the array to the proper error code and present that code?
If only zeros in the array there are no errors and I would like to present “None”

Thanks

EDIT:
This seems to work:

value_template: >
       {% if is_state('value_json.allarmi[0]', '1') %}
         Blade Blocked
       {% elif is_state('value_json.allarmi[1]', '1') %}
         Repositioning Error
       {% elif is_state('value_json.allarmi[2]', '1') %}
         Outside Wire
       {% elif is_state('value_json.allarmi[3]', '1') %}
         Blade Blocked
       {% elif is_state('value_json.allarmi[4]', '1') %}
         Outside Wire
       {% elif is_state('value_json.allarmi[5]', '1') %}
          Mover Tilted
       {% elif is_state('value_json.allarmi[6]', '1') %}
         Error
       {% else %}
         None
       {% endif %}

Just found a new development for the landroid

tried to build but it ends with an error.

Tried the docker too: nope.

You might want to give it a try