rgc99 / irrigation_unlimited

♒Irrigation controller for Home Assistant
MIT License
329 stars 49 forks source link

Tasmota Pulsetime Support #178

Open edoardop13 opened 2 months ago

edoardop13 commented 2 months ago

Hi, thank you for this nice project.

I was trying to implement it and design a new ui lovelace/mushroom card but I noticed that the script that turn on the valves doesn't have tasmota pulsetime support.

I use the pulsetime function in Sonoffs with Tasmota because if Home Assistant or internet fail I'm sure the valve will close.

This is an example of code with pulsetime

- service: mqtt.publish
        data_template:
          topic: >
            cmnd/{{ sonoff }}/pulsetime{{ valve }}
          payload: >
            {% set seconds = states('sensor.irrigation_' ~ cycle ~ '_' ~ zone ~ '') | int %}
            {% if seconds <= 11 %}
              {% set payload = 10 * seconds %}
            {% else %}
              {% set payload = 100 + seconds %}
            {% endif %}
            {{ payload | int }}

{{ sonoff }} is the name of the sonoff {{ valve }} is the number: 1,2,3 or 4

For the payload the script get the seconds that the user set and convert as indicated in the tasmota documentation.

Yes, I can create an automation that track the irrigation unlimited sensor for a specific zone and send this mqtt command, but is nicer that if it is possible this support is included in the irrigation unlimited integration.

rgc99 commented 2 months ago

Can you set up a Home Assistant MQTT switch like here?

edoardop13 commented 2 months ago

Yes, this is one switch:

- name: "Prato 2"
  state_topic: "stat/sonoff-elettrovalvole2/POWER4"
  command_topic: "cmnd/sonoff-elettrovalvole2/POWER4"
  availability_topic: "tele/sonoff-elettrovalvole2/LWT"
  icon: mdi:water-pump
  qos: 1
  payload_on: "ON"
  payload_off: "OFF"
  payload_available: "Online"
  payload_not_available: "Offline"
  retain: false

But doesn't works with pulsetime. It's a simple switch. Pulsetime require the amount of seconds for the ON state. The only way that I found is make an automation that track the irrigation unlimited sensor or change the irrigation unlimited code.

xal88 commented 2 months ago

Hello, have used an automation with state trigger and notify to set tasmota pulsetime. Using default of 15 min otherwise.

Automation:

alias: Relais Update Timer
description: Set relais timer, default to 15 min
trigger:
  - platform: state
    entity_id: binary_sensor.irrigation_unlimited_c1_z1
    to: "on"
condition: []
action:
  - variables:
      target: "{{'PulseTime' + state_attr( trigger.entity_id ,'relais')[1:] + '%20' }}"
      cmd: |-
        {% if state_attr( trigger.entity_id ,'current_duration') is none %}
          {{ target + '1000' }}
        {% else %}
          {% set t1 = state_attr( trigger.entity_id,  'current_duration') %}     
          {{ target + ( ( (t1.split(':')[0] | int *60 + t1.split(':')[1] | int ) * 60 ) + int(100) ) | string }}    
        {% endif %}
  - service: notify.gardenrelais
    data:
      message: "{{ cmd }}"
      title: Irrigation pulseTime update

Notify:

notify:
  - name: gardenrelais
    platform: rest
    resource: http://172.21.12.206/cm
    message_param_name: cmnd

Maybe this helps for a quick solution.

BR Alf

edoardop13 commented 2 months ago

Hello, have used an automation with state trigger and notify to set tasmota pulsetime. Using default of 15 min otherwise.

Automation:

alias: Relais Update Timer
description: Set relais timer, default to 15 min
trigger:
  - platform: state
    entity_id: binary_sensor.irrigation_unlimited_c1_z1
    to: "on"
condition: []
action:
  - variables:
      target: "{{'PulseTime' + state_attr( trigger.entity_id ,'relais')[1:] + '%20' }}"
      cmd: |-
        {% if state_attr( trigger.entity_id ,'current_duration') is none %}
          {{ target + '1000' }}
        {% else %}
          {% set t1 = state_attr( trigger.entity_id,  'current_duration') %}     
          {{ target + ( ( (t1.split(':')[0] | int *60 + t1.split(':')[1] | int ) * 60 ) + int(100) ) | string }}    
        {% endif %}
  - service: notify.gardenrelais
    data:
      message: "{{ cmd }}"
      title: Irrigation pulseTime update

Notify:

notify:
  - name: gardenrelais
    platform: rest
    resource: http://172.21.12.206/cm
    message_param_name: cmnd

Maybe this helps for a quick solution.

BR Alf

Yes, this is the quickest solution, but I don't understand why the notify.

xal88 commented 2 months ago

Yes, this is the quickest solution, but I don't understand why the notify.

Because I want to notify Tasmota how long it should open the zone relais, so the watering is not running endless if the close command does not arrive ( or someone klicks in the relais controll manually, then it stops after 15 minutes ). And the MQTT commands did not work reliable for me.

edoardop13 commented 2 months ago

Yes, this is the quickest solution, but I don't understand why the notify.

Because I want to notify Tasmota how long it should open the zone relais, so the watering is not running endless if the close command does not arrive ( or someone klicks in the relais controll manually, then it stops after 15 minutes ). And the MQTT commands did not work reliable for me.

Okay, so it's the same thing of my code with mqtt.publish in the first message