Noob question…
How do you guys integrate the mqtt topics into Home Assistant? Does anyone have an example?
I’m looking for a way to add switches and time selectors for the irrigation zones.
Noob question…
How do you guys integrate the mqtt topics into Home Assistant? Does anyone have an example?
I’m looking for a way to add switches and time selectors for the irrigation zones.
It took me sometime but I figured it out. Will share my configuration here for other benefit from.
My aim was to be able to select a zone and start the irrigation for a adjustable period of time. Next to that I wanted it to be flexible enough to be used in an automation in the future.
The UI elements:
The script (in Dutch)
##################################
# Irrigatie zone selectbox #
##################################
input_select:
irrigatie_zone_achtertuin:
name: Irrigatie zone achtertuin
options:
- Druppel slang
- Sproeiers
template:
- sensor:
- name: irrigatie_map_zone_achtertuin
state: >
{% set mapper =
{ 'Druppel slang':'1',
'Sproeiers':'2' } %}
{% set state = states('input_select.irrigatie_zone_achtertuin') %}
{% set id = mapper[state] if state in mapper %}
{{ id }}
input_text:
irrigatie_actieve_zone_achtertuin:
initial: inactive
##################################
# Irrigatie zone tijd selectie #
##################################
input_number:
irrigatie_timer_1_achtertuin:
name: Timer druppel slang
initial: 60
min: 1
max: 120
step: 1
irrigatie_timer_2_achtertuin:
name: Timer sproeiers
initial: 45
min: 1
max: 120
step: 1
################################################
# Geselecteerde Sproeier switch script & timer #
################################################
timer:
irrigatie_tijd_resterend_achtertuin:
name: Resterende tijd
duration: "00:00:00"
switch:
- platform: template
switches:
irrigatie_achtertuin:
friendly_name: "Sproeier aan/uit"
turn_on:
- service: script.turn_on
data:
entity_id: script.irrigatie_aan_achtertuin
- service: timer.start
target:
entity_id: timer.irrigatie_tijd_resterend_achtertuin
data:
duration: "{{ states('input_number.irrigatie_timer_' ~ states('sensor.irrigatie_map_zone_achtertuin') ~ '_achtertuin') | int * 60 }}"
- service: input_text.set_value
target:
entity_id: input_text.irrigatie_actieve_zone_achtertuin
data:
value: "{{ states('sensor.irrigatie_map_zone_achtertuin') }}"
turn_off:
- service: script.turn_on
data:
entity_id: script.irrigatie_uit_achtertuin
- service: timer.finish
target:
entity_id: timer.irrigatie_tijd_resterend_achtertuin
- service: input_text.set_value
target:
entity_id: input_text.irrigatie_actieve_zone_achtertuin
data:
value: inactive
icon_template: >-
{% if is_state('switch.hunterirrigation', 'on') %}
mdi:water-pump
{% else %}
mdi:water-pump-off
{% endif %}
##################################
# Aanroepen naar mqtt #
##################################
script:
irrigatie_aan_achtertuin:
alias: Sproeier aan
sequence:
- service: mqtt.publish
data_template:
topic_template: hunter/X-CORE/zone/{{ states('sensor.irrigatie_map_zone_achtertuin') }}
payload_template: >
{ "action": "start", "time": {{ states('input_number.irrigatie_timer_' ~ states('sensor.irrigatie_map_zone_achtertuin') ~ '_achtertuin') | int }} }"
irrigatie_uit_achtertuin:
alias: Sproeier uit
sequence:
- service: mqtt.publish
data_template:
topic_template: hunter/X-CORE/zone/{{ states('input_text.irrigatie_actieve_zone_achtertuin') }}
payload_template: >
{ "action": "stop" }
##################################
# Reset switch na aflopen timer #
##################################
automation:
- id: '1655392256832'
alias: Irrigatie - reset switch wanneer timer klaar is
description: ''
trigger:
- platform: event
event_type: timer.finished
event_data:
entity_id: timer.irrigatie_tijd_resterend_achtertuin
condition: []
action:
- service: switch.turn_off
data: {}
target:
entity_id: switch.irrigatie_achtertuin
mode: single
Last week a user asked me about how I approached integrating the Hunter X-Core via DM. To help out future users getting started I will also post my answer to him in this topic.
If you don’t want to communicate to the WeMos D1 Mini Pro via mqtt skip this step
First you setup a mqtt broker to communicate with the WeMos D1 Mini Pro (mosquitto).
I prefer communication via mqtt since you don’t need to know the WeMos IP address. And therefor don’t have to configure a static IP.
Install the software on the WeMos D1 Mini Pro as described on the Github page.
Make sure to fill in all requested information when you configure the WeMos via the web interface otherwise the WeMos won’t start properly and end up in a boot loop.
If you don’t want to use mqtt you have to fill in something in the web interface configuration otherwise you will end up in the boot loop.
Now follow the guide on Github to connect the WeMos to The Hunter X-Core. The documentation linked to from the start post is also worth reading.
The WeMos fitted inside the Hunter’s case so the risk of someone accidently damaging it is pretty small.
Use MQTT-Explorer to connect to your mosquito broker. If I remember correctly the WeMos should send a message to the broker on start up. That message will include the mqtt address. In my case this was hunter/X-CORE
.
At this point you can copy past my code to a Home Assistant Package and modify to your preferences. As far as I understand a package is just a yaml file where you can bundle multiple entities with a certain purpose.
Add packages to your configuration.yaml (I added it at the top).
homeassistant:
packages: !include_dir_named packages
Now add the configuration I posted in the topic to a package, in my case that is config/packages/irrigatie.yaml
I’ve set up the project as described (thank you dehaas). Wemos is connected to the 24VAC on the hunter using the 3.3V output from the board. I see the commands comming through in my mqtt broker and I’m getting a result back from the board.
So it all seems to work great except the fact that my hunter is doing nothing if I send a command.
Is there any way of checking if the Wemos is communicating correctly with my hunter?
Sorry for the noob question. But how can I get it on an ESP32 board? Is it possible to get me started with esptool? Thanks in advance!
@dehaas Your script package helped me a lot. I translated it to english and added some more zones. Here is my updated version
##################################
# Irrigate zone selectbox #
##################################
input_select:
irrigate_zone:
name: Irrigate zone
options:
- zone1
- zone2
- zone2
- zone3
- zone4
- zone5
- zone6
- zone7
template:
- sensor:
- name: irrigate_map_zone
state: >
{% set mapper =
{ 'zone1':'1',
'zone2':'2',
'zone3':'3',
'zone4':'4',
'zone5':'5',
'zone6':'6',
'zone7':'7'} %}
{% set state = states('input_select.irrigate_zone') %}
{% set id = mapper[state] if state in mapper %}
{{ id }}
input_text:
irrigation_active_zone:
initial: inactive
##################################
# Irrigation zone time selection #
##################################
input_number:
irrigate_timer_1:
name: Timer zone1
initial: 60
min: 1
max: 120
step: 1
irrigate_timer_2:
name: Timer zone2
initial: 60
min: 1
max: 120
step: 1
irrigate_timer_3:
name: Timer zone3
initial: 60
min: 1
max: 120
step: 1
irrigate_timer_4:
name: Timer zone4
initial: 60
min: 1
max: 120
step: 1
irrigate_timer_5:
name: Timer zone5
initial: 60
min: 1
max: 120
step: 1
irrigate_timer_6:
name: Timer zone6
initial: 60
min: 1
max: 120
step: 1
irrigate_timer_7:
name: Timer zone7
initial: 60
min: 1
max: 120
step: 1
################################################
# Selected Sprinkler switch script & timer #
################################################
timer:
irrigation_time_remaining:
name: Remaining Time
duration: "00:00:00"
switch:
- platform: template
switches:
irrigate_lawn:
friendly_name: "Sprinkler On/Off"
turn_on:
- service: script.turn_on
data:
entity_id: script.irrigation_on
- service: timer.start
target:
entity_id: timer.irrigation_time_remaining
data:
duration: "{{ states('input_number.irrigate_timer_' ~ states('sensor.irrigate_map_zone')) | int * 60 }}"
- service: input_text.set_value
target:
entity_id: input_text.irrigation_active_zone
data:
value: "{{ states('sensor.irrigate_map_zone') }}"
turn_off:
- service: script.turn_on
data:
entity_id: script.irrigation_off
- service: timer.finish
target:
entity_id: timer.irrigation_time_remaining
- service: input_text.set_value
target:
entity_id: input_text.irrigation_active_zone
data:
value: inactive
icon_template: >-
{% if is_state('switch.irrigate_lawn', 'on') %}
mdi:water-pump
{% else %}
mdi:water-pump-off
{% endif %}
##################################
# Invoke mqtt #
##################################
script:
irrigation_on:
alias: Sprinkler On
sequence:
- service: mqtt.publish
data_template:
topic_template: hunter/X-CORE/zone/{{ states('sensor.irrigate_map_zone') }}
payload_template: >
{ "action": "start", "time": {{ states('input_number.irrigate_timer_' ~ states('sensor.irrigate_map_zone')) | int }} }
irrigation_off:
alias: Sprinkler Off
sequence:
- service: mqtt.publish
data_template:
topic_template: hunter/X-CORE/zone/{{ states('input_text.irrigation_active_zone') }}
payload_template: >
{ "action": "stop" }
##################################
# Reset switch when timer finishes #
##################################
automation:
- id: '1655392256832'
alias: Irrigatie - reset switch wanneer timer klaar is
description: ''
trigger:
- platform: event
event_type: timer.finished
event_data:
entity_id: timer.irrigation_time_remaining
condition: []
action:
- service: switch.turn_off
data: {}
target:
entity_id: switch.irrigate_lawn
mode: single
I also made a similar UI card as yours. I added a conditonal card which will show corresponding zone time input. I tried template entity card, to conditionally show the corresponding zone time input, but it quite doesn’t do what I wanted :
type: entities
entities:
- input_select.irrigate_zone
- type: conditional
conditions:
- entity: sensor.irrigate_map_zone
state: '1'
row:
entity: input_number.irrigate_timer_1
- type: conditional
conditions:
- entity: sensor.irrigate_map_zone
state: '2'
row:
entity: input_number.irrigate_timer_2
- type: conditional
conditions:
- entity: sensor.irrigate_map_zone
state: '3'
row:
entity: input_number.irrigate_timer_3
- type: conditional
conditions:
- entity: sensor.irrigate_map_zone
state: '4'
row:
entity: input_number.irrigate_timer_4
- type: conditional
conditions:
- entity: sensor.irrigate_map_zone
state: '5'
row:
entity: input_number.irrigate_timer_5
- type: conditional
conditions:
- entity: sensor.irrigate_map_zone
state: '6'
row:
entity: input_number.irrigate_timer_6
- type: conditional
conditions:
- entity: sensor.irrigate_map_zone
state: '7'
row:
entity: input_number.irrigate_timer_7
- type: custom:template-entity-row
entity: input_number.irrigate_timer_{{ states('sensor.irrigate_map_zone')}}
- entity: switch.irrigate_lawn
- entity: timer.irrigation_time_remaining
- input_text.irrigation_active_zone
Hi,
Thanks that’s helpful !
Do you use a wemos D1 mini ? I’ve got one but the wifi signal is just catastrophic… even if I soldered the zero resistor in order to use an external antenna… I don’t know what to do, I can’t event ping the board at 5 meters from the box
I use a Wemis D1 Mini Pro. The wifi signal on my board is fine even without soldering the zero resistor.
Maybe your board is faulty, do you have a second board to check this?
Good day, do you happen to have a connection diagram between the Wemos and Hunter? The one linked in the GitHub is leading to a 404 not found.
Looks like the links in the documentation aren’t correct, the image is still there.
hunter-wifi/docs/images/connection.png at master · anubisg1/hunter-wifi · GitHub
Thank you. I’ll have a look.
Hi,
I’m using the ecodina fw on a wemos d1 mini connected to a X-core 601, I’ve been able to use it with REST API, unluckily I’ve not been able to integrate with MQTT.
The strange thing is if i use pre build image found on github the wemos keeps rebooting.
Building from source and uploading the FW then the wemos doesn’t reboot, the API are available but not the MQTT, anyone has been able to do it?
Hi @dehaas
I installed prebuild firmware but do not know how to manage mqtt setup. When I connect to WateringSystemAP I can only setup wifi I want to connect to, not mqtt. Could you please help to solve this? Thank you.
Update:
I installed the old veraion of bin file. Now downloaded the latest one from link below and I am able to add mqtt address. Release New features: MQTT · ecodina/hunter-wifi · GitHub
Thanks @roobaru & @dehaas for posting your work, I’ve created my own version based on mushroom-ui, with custom card which toggles watering and includes countdown timer:
Since mine Hunter XCORE has only 4 zones total (and only 3 wired), I’ve removed extra inputs from the script and added automation to listen to Hunters MQTT topic for command results.
Whole setup is documented on this github repo, for anyone interested.
Thanks @empi.sk
But both links in English do not work !
https://github.com/marek-polak/hunter-wifi/blob/e9154a2be7fb64a44dbd69116ab3ffb53e7874da/docs/pages/docs/scripts/irrigation-control.en.yaml
https://github.com/marek-polak/hunter-wifi/blob/e9154a2be7fb64a44dbd69116ab3ffb53e7874da/docs/pages/docs/scripts/custom-button-card-templates.en.yaml
Thank you once again to everyone!
Everything works perfectly but in the logs I have two error
1
Logger: homeassistant.components.automation.mqtt_hook_irrigation
Source: components/automation/init.py:680
Integration: Automation (documentation, issues)
First occurred: 4:54:55 PM (4 occurrences)
Last logged: 4:55:13 PM
Error while executing automation automation.mqtt_hook_irrigation: extra keys not allowed @ data[‘trigger.payload_json’]
2
Logger: homeassistant.components.automation.mqtt_hook_irrigation
Source: helpers/script.py:420
Integration: Automation (documentation, issues)
First occurred: 4:54:55 PM (4 occurrences)
Last logged: 4:55:13 PM
mqtt_hook_Irrigation: Error executing script. Invalid data for call_service at pos 2: extra keys not allowed @ data[‘trigger.payload_json’]
And 3 warnings
1
Logger: homeassistant.components.template.template_entity
Source: components/template/template_entity.py:412
Integration: Template (documentation, issues)
First occurred: 4:54:55 PM (7 occurrences)
Last logged: 4:55:12 PM
Template loop detected while processing event: <Event state_changed[L]: entity_id=switch.irrigate_lawn, old_state=<state switch.irrigate_lawn=off; assumed_state=True, icon=mdi:water-pump-off, friendly_name=Sprinkler On/Off @ 2023-10-04T16:50:32.953936+03:00>, new_state=<state switch.irrigate_lawn=on; assumed_state=True, icon=mdi:water-pump-off, friendly_name=Sprinkler On/Off @ 2023-10-04T16:54:55.315088+03:00>>, skipping template render for Template[{% if is_state(‘switch.irrigate_lawn’, ‘on’) %} mdi:water-pump {% else %} mdi:water-pump-off {% endif %}]
Template loop detected while processing event: <Event state_changed[L]: entity_id=switch.irrigate_lawn, old_state=<state switch.irrigate_lawn=on; assumed_state=True, icon=mdi:water-pump, friendly_name=Sprinkler On/Off @ 2023-10-04T16:54:55.315088+03:00>, new_state=<state switch.irrigate_lawn=off; assumed_state=True, icon=mdi:water-pump, friendly_name=Sprinkler On/Off @ 2023-10-04T16:54:59.291081+03:00>>, skipping template render for Template[{% if is_state(‘switch.irrigate_lawn’, ‘on’) %} mdi:water-pump {% else %} mdi:water-pump-off {% endif %}]
Template loop detected while processing event: <Event state_changed[L]: entity_id=switch.irrigate_lawn, old_state=<state switch.irrigate_lawn=off; assumed_state=True, icon=mdi:water-pump, friendly_name=Sprinkler On/Off @ 2023-10-04T16:54:59.291081+03:00>, new_state=<state switch.irrigate_lawn=on; assumed_state=True, icon=mdi:water-pump, friendly_name=Sprinkler On/Off @ 2023-10-04T16:55:08.987897+03:00>>, skipping template render for Template[{% if is_state(‘switch.irrigate_lawn’, ‘on’) %} mdi:water-pump {% else %} mdi:water-pump-off {% endif %}]
Template loop detected while processing event: <Event state_changed[L]: entity_id=switch.irrigate_lawn, old_state=<state switch.irrigate_lawn=on; assumed_state=True, icon=mdi:water-pump, friendly_name=Sprinkler On/Off @ 2023-10-04T16:55:08.987897+03:00>, new_state=<state switch.irrigate_lawn=off; assumed_state=True, icon=mdi:water-pump, friendly_name=Sprinkler On/Off @ 2023-10-04T16:55:12.589525+03:00>>, skipping template render for Template[{% if is_state(‘switch.irrigate_lawn’, ‘on’) %} mdi:water-pump {% else %} mdi:water-pump-off {% endif %}]
2
Logger: homeassistant.helpers.script.sprinkler_on_off
Source: helpers/script.py:1509
First occurred: 4:54:59 PM (2 occurrences)
Last logged: 4:55:12 PM
Sprinkler On/Off: Already running
3
Logger: homeassistant.components.input_select
Source: components/input_select/init.py:95
Integration: Input select (documentation, issues)
First occurred: 4:50:31 PM (1 occurrences)
Last logged: 4:50:31 PM
Input select ‘Irrigate zone’ with options [‘zone1’, ‘zone2’, ‘zone2’, ‘zone3’, ‘zone4’, ‘zone5’, ‘zone6’, ‘zone7’, ‘zone8’] had duplicated options, the duplicates have been removed
Thank you
Thanks for info - I’ve fixed the links in repository, as well as errors/warnings in the scripts - all but Sprinkler On/Off: Already running
, which I think has something to do with timer.irrigation_time_remaining
running, but I could use some help.
Thanks empi.sk,
I saw in your version, at the wifi portal there are an extra line to fill that say something like MQTT protocol (0/1) … or something like this, i can connect to mi wifi network but there is no way to ESP connect to the MQTT broqquer running in home assitant, could be something related to that confinguration that i am leaving in gray as it come prefilled? Thanks in advance.
Hi @pjmasci, which version did you flash on the d1? As mentioned in repo, for the mqtt to work, you should use the v1.0.0.
Afterwards, when logged into WateringSystemAP, you should be able to save MQTT settings:
select 1. option “Configure WiFi”
Add ssid/password to your WiFi, and MQTT server connecttion settings
raspi3b.local
I’ve tryied the 1.0.0 fw but if I set and enable mqtt my wemos goes in a boot loop. What flashing procedure do you follow?