Netro Integration

Hi,

I would like to suggest to evaluate the possibility of integrating Netro products (http://www.netrohome.com/), especially the sprinkler sytems, into Home Assistant.

This would allow automation of the sprinkler system at house.

I’m also interested in this…

Please

I’m also interested in this…

Thanks

Also interested.

Me too please !

Anyone done this yet - I am also interested

1 Like

One up!!

After this too!

1 Like

Yes, please! I am also interested.

Dear all,
I’ve just heard that Netro has published their own API. Did someone already examine this ?

Here is the link to the information regarding the API : https://www.netrohome.com/shop/articles/10

@Bowie @alnavasa @juanbrunette @virgilinfo @Yoryino @StefanoGiu @iphoust84
Guys,
As indicated in my post, after a lot of pushing, Netro has published their API. As I’m a newbie in this space, and you might have experience, please have a look and maybe create something ?

Here you find more information on their API : https://www.netrohome.com/shop/articles/10

I have Zero coding knowledge, but that api looks easy to start dealing with, not that sophisticated.

I created the following sensors:

  - platform: rest
    name: Centralina Irrigazione - Zona 1
    json_attributes_path: "$.[0]"
    json_attributes:
      - local_start_time
      - local_end_time
      - local_date
      - source
      - status
    resource_template: http://api.netrohome.com/npa/v1/schedules.json?key=XXXXXXXXXXXX&start_date={{now().strftime('%Y-%m-%d')}}&end_date={{now().strftime('%Y-%m-%d')}}&zones=[1]
    scan_interval: 600
    value_template: "{{ value_json.data.schedules[0].status }}"    
  - platform: rest
    name: Centralina Irrigazione - Zona 2
    json_attributes_path: "$.[0]"
    json_attributes:
      - local_start_time
      - local_end_time
      - local_date
      - source
      - status
    resource_template: http://api.netrohome.com/npa/v1/schedules.json?key=XXXXXXXXXXXX&start_date={{now().strftime('%Y-%m-%d')}}&end_date={{now().strftime('%Y-%m-%d')}}&zones=[2]
    scan_interval: 600
    value_template: "{{ value_json.data.schedules[0].status }}"    
  - platform: rest
    name: Centralina Irrigazione - Zona 3
    json_attributes_path: "$.[0]"
    json_attributes:
      - local_start_time
      - local_end_time
      - local_date
      - source
      - status
    resource_template: http://api.netrohome.com/npa/v1/schedules.json?key=XXXXXXXXXXXX&start_date={{now().strftime('%Y-%m-%d')}}&end_date={{now().strftime('%Y-%m-%d')}}&zones=[3]
    scan_interval: 600
    value_template: "{{ value_json.data.schedules[0].status }}"    
  - platform: rest
    name: Centralina Irrigazione - Zona 4
    json_attributes_path: "$.[0]"
    json_attributes:
      - local_start_time
      - local_end_time
      - local_date
      - source
      - status
    resource_template: http://api.netrohome.com/npa/v1/schedules.json?key=XXXXXXXXXXXX&start_date={{now().strftime('%Y-%m-%d')}}&end_date={{now().strftime('%Y-%m-%d')}}&zones=[4]
    scan_interval: 600
    value_template: "{{ value_json.data.schedules[0].status }}"    
  - platform: rest
    name: Centralina Irrigazione - Zona 5
    json_attributes_path: "$.[0]"
    json_attributes:
      - local_start_time
      - local_end_time
      - local_date
      - source
      - status
    resource_template: http://api.netrohome.com/npa/v1/schedules.json?key=XXXXXXXXXXXX&start_date={{now().strftime('%Y-%m-%d')}}&end_date={{now().strftime('%Y-%m-%d')}}&zones=[5]
    scan_interval: 600
    value_template: "{{ value_json.data.schedules[0].status }}"    
  - platform: rest
    name: Centralina Irrigazione - Zona 6
    json_attributes_path: "$.[0]"
    json_attributes:
      - local_start_time
      - local_end_time
      - local_date
      - source
      - status
    resource_template: http://api.netrohome.com/npa/v1/schedules.json?key=XXXXXXXXXXXX&start_date={{now().strftime('%Y-%m-%d')}}&end_date={{now().strftime('%Y-%m-%d')}}&zones=[6]
    scan_interval: 600
    value_template: "{{ value_json.data.schedules[0].status }}" 
  - platform: rest
    name: Centralina Irrigazione
    json_attributes:
      - data
    resource_template: https://api.netrohome.com/npa/v1/info.json?key=XXXXXXXXXXXX
    scan_interval: 60
    value_template: "{{ value_json.data.device.status }}" 
  - platform: template
    sensors:
      centralina_irrigazione_name:
        value_template: >
          {{ state_attr('sensor.centralina_irrigazione', 'data')['device']['name'] }}
      centralina_irrigazione_serial:
        value_template: >
          {{ state_attr('sensor.centralina_irrigazione', 'data')['device']['serial'] }}             
      centralina_irrigazione_zone_num:
        value_template: >
          {{ state_attr('sensor.centralina_irrigazione', 'data')['device']['zone_num'] }}
      centralina_irrigazione_status:
        value_template: >
          {{ state_attr('sensor.centralina_irrigazione', 'data')['device']['status'] }}
      centralina_irrigazione_version:
        value_template: >
          {{ state_attr('sensor.centralina_irrigazione', 'data')['device']['version'] }}
      centralina_irrigazione_sw_version:
        value_template: >
          {{ state_attr('sensor.centralina_irrigazione', 'data')['device']['sw_version'] }}
      centralina_irrigazione_zone1_name:
        value_template: >
          {{ state_attr('sensor.centralina_irrigazione', 'data')['device']['zones'][0]['name'] }}
      centralina_irrigazione_zone2_name:
        value_template: >
          {{ state_attr('sensor.centralina_irrigazione', 'data')['device']['zones'][1]['name'] }}
      centralina_irrigazione_zone3_name:
        value_template: >
          {{ state_attr('sensor.centralina_irrigazione', 'data')['device']['zones'][2]['name'] }}
      centralina_irrigazione_zone4_name:
        value_template: >
          {{ state_attr('sensor.centralina_irrigazione', 'data')['device']['zones'][3]['name'] }}
      centralina_irrigazione_zone5_name:
        value_template: >
          {{ state_attr('sensor.centralina_irrigazione', 'data')['device']['zones'][4]['name'] }}
      centralina_irrigazione_zone6_name:
        value_template: >
          {{ state_attr('sensor.centralina_irrigazione', 'data')['device']['zones'][5]['name'] }}

And then the following scripts that I use on the lovelace to start and stop the watering:

water_a_zone:
  alias: Innaffia una zona
  sequence:
   - choose:
      - conditions:
          - condition: template
            value_template: >
                        {{ states["sensor.centralina_irrigazione"].state == 'ONLINE' }}
        sequence:
          - service: rest_command.water_start
            data_template:
                time: >
                        {{minuti}}
                zone: >
                        {{zona}}   
      - conditions:
          - condition: template
            value_template: >
                    {{ states["sensor.centralina_irrigazione"].state == 'WATERING' }}
        sequence:
          - service: rest_command.water_stop
   - service: notify.allarme
     data_template:
       title: >-
            {% if (states["sensor.centralina_irrigazione"].state == 'ONLINE')%} 
                    đź’§ *Innaffia Zona*
            {% elif (states["sensor.centralina_irrigazione"].state == 'WATERING')%} 
                    đź’§ *Ferma Irrigazione*
            {% elif (states["sensor.centralina_irrigazione"].state == 'OFFLINE')%} 
                    đź’§ *Centralina Offline*
            {% else %}
                    đź’§ *Stato Centralina Sconosciuto*
            {% endif %}
       message: >-
            {% if (states["sensor.centralina_irrigazione"].state == 'ONLINE')%} 
                    Innaffio la zona {{zona}} per {{minuti}} minuti
            {% elif (states["sensor.centralina_irrigazione"].state == 'WATERING')%} 
                    Fermo l'irrigazione
            {% elif (states["sensor.centralina_irrigazione"].state == 'OFFLINE')%} 
                    Centralina Offline
            {% else %}
                    Stato Centralina Sconosciuto
            {% endif %}
   - delay:
       seconds: 3
   - service: homeassistant.update_entity
     entity_id: sensor.centralina_irrigazione
   - service: homeassistant.update_entity
     entity_id: sensor.centralina_irrigazione_zona_1
   - service: homeassistant.update_entity
     entity_id: sensor.centralina_irrigazione_zona_2
   - service: homeassistant.update_entity
     entity_id: sensor.centralina_irrigazione_zona_3
   - service: homeassistant.update_entity
     entity_id: sensor.centralina_irrigazione_zona_4
   - service: homeassistant.update_entity
     entity_id: sensor.centralina_irrigazione_zona_5
   - service: homeassistant.update_entity
     entity_id: sensor.centralina_irrigazione_zona_6
   - service: homeassistant.update_entity
     entity_id: sensor.centralina_irrigazione_name
   - service: homeassistant.update_entity
     entity_id: sensor.centralina_irrigazione_serial
   - service: homeassistant.update_entity
     entity_id: sensor.centralina_irrigazione_status
   - service: homeassistant.update_entity
     entity_id: sensor.centralina_irrigazione_sw_version
   - service: homeassistant.update_entity
     entity_id: sensor.centralina_irrigazione_version
   - service: homeassistant.update_entity
     entity_id: sensor.centralina_irrigazione_zone1_name
   - service: homeassistant.update_entity
     entity_id: sensor.centralina_irrigazione_zone2_name
   - service: homeassistant.update_entity
     entity_id: sensor.centralina_irrigazione_zone3_name
   - service: homeassistant.update_entity
     entity_id: sensor.centralina_irrigazione_zone4_name
   - service: homeassistant.update_entity
     entity_id: sensor.centralina_irrigazione_zone5_name
   - service: homeassistant.update_entity
     entity_id: sensor.centralina_irrigazione_zone6_name
   - service: homeassistant.update_entity
     entity_id: sensor.centralina_irrigazione_zone_num

with rest_command:

water_start:
    url: https://api.netrohome.com/npa/v1/water.json
    method: POST
    headers:
      accept: "application/json, text/html"
      user-agent: 'Mozilla/5.0 {{ useragent }}'
    payload: '{"key":"XXXXXXXXXXXX", "zones": [{{zone}}], "duration":{{time}} }'
    content_type:  'application/json; charset=utf-8'
    verify_ssl: true

water_stop:
    url: https://api.netrohome.com/npa/v1/stop_water.json
    method: POST
    headers:
      accept: "application/json, text/html"
      user-agent: 'Mozilla/5.0 {{ useragent }}'
    payload: '{"key":"XXXXXXXXXXXX" }'
    content_type:  'application/json; charset=utf-8'
    verify_ssl: true

You willl need to replace XXXXXXX with your tokenkey…

3 Likes

This part will send a message to my TelegramBot

I would also love to see an integration. If I manage to get my head around Python I may give it a try.

In the meantime, following @StefanoGiu’s code, I’ve wrapped it all in a package with one API call for all the sensors to avoid reaching the quota.

I’ve got 6 zones but only pasted the code for 2 for simplicity but it can be adapted to N zones.

rest:
  - resource_template: http://api.netrohome.com/npa/v1/schedules.json?key={{states('sensor.netro_api_key')}}&start_date={{utcnow().strftime('%Y-%m-%d')}}
    scan_interval: 90
    sensor:
      - name: Netro Zone 1 Raw
        value_template: >
          {% set current_zone = ( value_json.data.schedules | selectattr("zone","eq", 1) | list )  %}
          {{ current_zone | selectattr("status","ne","EXECUTED") | list | last }}
      - name: Netro Zone 2 Raw
        value_template: >
          {% set current_zone = ( value_json.data.schedules | selectattr("zone","eq", 2) | list )  %}
          {{ current_zone | selectattr("status","ne","EXECUTED") | list | last }}


rest_command:
  netro_irrigation_start:
      url: https://api.netrohome.com/npa/v1/water.json
      method: POST
      headers:
        accept: "application/json, text/html"
        user-agent: 'Mozilla/5.0 {{ useragent }}'
      payload: '{"key":"{{states("sensor.netro_api_key")}}", "zones": [{{zone}}], "duration":{{duration}} }'
      content_type:  'application/json; charset=utf-8'
      verify_ssl: true
  netro_irrigation_stop:
      url: https://api.netrohome.com/npa/v1/stop_water.json
      method: POST
      headers:
        accept: "application/json, text/html"
        user-agent: 'Mozilla/5.0 {{ useragent }}'
      payload: '{"key":"{{states("sensor.netro_api_key")}}" }'
      content_type:  'application/json; charset=utf-8'
      verify_ssl: true

script:
  netro_irrigation_start:
    description: Starts Netro Irrigation for a given zone
    sequence:
      - service: rest_command.netro_irrigation_start
        data_template:
          duration: "{{duration}}"
          zone: "{{zone}}"
      - delay: 
          seconds: 5
      - service: homeassistant.update_entity
        entity_id: sensor.netro_zone_1_raw # any zone would do
  netro_irrigation_stop:
    description: Stops current Netro Irrigation
    sequence:
      - service: rest_command.netro_irrigation_stop
      - delay: 
          seconds: 5
      - service: homeassistant.update_entity
        entity_id: sensor.netro_zone_1_raw


    
sensor:
  - platform: template
    sensors:
      netro_api_key:
        friendly_name: "Netro API Key"
        value_template: !secret netro_key
      netro_zone_1:
        friendly_name: "Netro Zone 1 Status"
        value_template: >  
          {%- set val = ((states('sensor.netro_zone_1_raw') or "{}") | replace("'",'"') | from_json).status %}
          {{- "on" if val == "EXECUTING" else "scheduled" if val == "VALID" else "off" }}
        attribute_templates:
          start_time: >  
            {{ ((states('sensor.netro_zone_1_raw') or "{}") | replace("'",'"') | from_json).start_time }}
          end_time: >  
            {{ ((states('sensor.netro_zone_1_raw') or "{}") | replace("'",'"') | from_json).end_time }}
          local_start_time: >  
            {{ ((states('sensor.netro_zone_1_raw') or "{}") | replace("'",'"') | from_json).local_start_time }}
          local_end_time: >  
            {{ ((states('sensor.netro_zone_1_raw') or "{}") | replace("'",'"') | from_json).local_end_time }}
          duration_minutes: >
            {%- set start_time = ((states('sensor.netro_zone_1_raw') or "{}") | replace("'",'"') | from_json).start_time  %}
            {%- set end_time = ((states('sensor.netro_zone_1_raw') or "{}") | replace("'",'"') | from_json).end_time  %}
            {{- ((as_timestamp(end_time) - as_timestamp(start_time)) / 60) | int  }}
          source: >  
            {{ ((states('sensor.netro_zone_1_raw') or "{}") | replace("'",'"') | from_json).source }}
      netro_zone_2:
        friendly_name: "Netro Zone 2 Status"
        value_template: >  
          {%- set val = ((states('sensor.netro_zone_2_raw') or "{}") | replace("'",'"') | from_json).status %}
          {{- "on" if val == "EXECUTING" else "scheduled" if val == "VALID" else "off" }}
        attribute_templates:
          start_time: >  
            {{ ((states('sensor.netro_zone_2_raw') or "{}") | replace("'",'"') | from_json).start_time }}
          end_time: >  
            {{ ((states('sensor.netro_zone_2_raw') or "{}") | replace("'",'"') | from_json).end_time }}
          local_start_time: >  
            {{ ((states('sensor.netro_zone_2_raw') or "{}") | replace("'",'"') | from_json).local_start_time }}
          local_end_time: >  
            {{ ((states('sensor.netro_zone_2_raw') or "{}") | replace("'",'"') | from_json).local_end_time }}
          duration_minutes: >
            {%- set start_time = ((states('sensor.netro_zone_2_raw') or "{}") | replace("'",'"') | from_json).start_time  %}
            {%- set end_time = ((states('sensor.netro_zone_2_raw') or "{}") | replace("'",'"') | from_json).end_time  %}
            {{- ((as_timestamp(end_time) - as_timestamp(start_time)) / 60) | int  }}
          source: >  
            {{ ((states('sensor.netro_zone_2_raw') or "{}") | replace("'",'"') | from_json).source }}
   
switch:
  - platform: template
    switches:
      netro_zone_1:
        value_template: "{{ is_state('sensor.netro_zone_1','on')}}"
        turn_on:
          service: script.netro_irrigation_start
          data:
            zone: "1"
            duration: "5"
        turn_off:
          service: script.netro_irrigation_stop
      netro_zone_2:
        value_template: "{{ is_state('sensor.netro_zone_2','on')}}"
        turn_on:
          service: script.netro_irrigation_start
          data:
            zone: "2"
            duration: "5"
        turn_off:
          service: script.netro_irrigation_stop

Hope it helps!

3 Likes

Thank you, this was really helpful to me! Does anyone know how i can format the date time for outputting something like this?

{{ ((states('sensor.netro_front_zone_raw') or "{}") | replace("'",'"') | from_json).start_time }}

At the moment it outputs canonical “2021-05-30T06:00:00” but i would just like it to display like “Sunday, May 30, 06:00”

I’m a newbie at this so would appreciate any help :slight_smile:

I’m presently using a 6 zones Rain Bird ESP-TM2 but saw the Netro 12 zones on Amazon. Is this easy to integrate into hassio?

I found Netro relatively easy to integrate. Just need some help with formatting etc.

1 Like

How shall I do to integrate in my HA? I have Hassio. I understand this is Python.

I’ll see if i can mimic my rainbird Lovelace config…

2 Likes