How to use "trigger" time feature in switch component

Hi,
I am trying to automate my newly made sprinklers using HA.
It is absolutely important that the sprinklers turn off even the HA server hangs. Fortunately cc2530 and wonderful https://ptvo.info/ support the feature to automatically turn off the relay in hardware independent of HA.
I only need to send a command like this:
mosquitto_pub -t zigbee2mqtt/device_entity_id/l1/set -m ‘{“trigger”: 10000}’

as documented here: here

I was not able to find any possible way to use that feature in Home assistant.
If it is not already there I am willing to create a pull request probably to add the feature to the ‘switch’ or any other other proper component.

You could add a timed automation that sends a mqtt_publish service call to that topic with the specific payload.

You might also be able to modify your MQTT switch to use a payload_on that passes the {“trigger”: 10000} as part of the command. I’ve not dealt with Zigbee2MQTT, so I’m not sure how it would work if you have discovery turned on.

You could create a template switch and for the turn on service call a script that contains the services you need. which could include a mosquitto publish command.

Or if that command above actually turns on the relay too then you can call the mosquitto publish service directly from the “turn_on:” section.

Did @smirzai already manage to get it done via the template switch?

1 Like

Actually I need the feature as an assurance in case something happens to the ha server or its connection to the device. Any feature in HA will not be useful in this case.

@finity Please see my reply to @code-in-progress

@Doublet Yes, it was fixed in a proper way.
Please check https://ptvo.info/zigbee-configurable-firmware-features/ search for “trigger” under section " zigbee2MQTT commands"

sets the output to the HIGH state for N milliseconds, then resets to LOW.
Topic: z2m/[friedly_name]/[channel]/set
Channel: l1, l2, l3 … l8
Payload: {trigger: 5000}

just use shell command

or you can finagle this with a MQTT switch. You have many options

like this?

shell_command: 
  sprinkler: 'mosquitto_pub -t z2m/device_entity_id/l1/set -m ‘{“trigger”: 10000}’

Great, would you mind sharing that piece of code?

yes, exactly like that. I am working on the the hardware so I cannot test it now and 100% confirm it, but it should work. As far as I know home assistant does not support the feature directly and you have to use a service to send mqtt message directly

Looks like a useful possible contribution.

I am going to try via this route

My PTVO device is 0x00124b00097331f3

The MQTT switch:

- platform: "mqtt"
    unique_id: test
    name: "Test Switch"
    state_topic: "zigbee2mqtt/0x00124b00097331f3"
    availability_topic: "zigbee2mqtt/bridge/state"
    payload_off: "OFF"
    payload_on: "{“trigger”: 10000}"
    value_template: "{{ value_json.state_l1 }}"
    command_topic: "zigbee2mqtt/0x00124b00097331f3/l1/set"   
    optimistic: false
    retain: true

When I switch on I get this error:

Zigbee2MQTT:error 2020-11-05 20:56:09: Invalid JSON '{“trigger”: 10000}', skipping...

any ideas?

your payload is not a valid json. try removing the quotation around “trigger” also replacing them with single quotes or escaping them

Tried it:

  - platform: mqtt
    unique_id: test
    name: "Test Switch"
    state_topic: "zigbee2mqtt/0x00124b00097331f3"
    availability_topic: "zigbee2mqtt/bridge/state"
    payload_off: "OFF"
    payload_on: '{trigger: 10000}'
    value_template: "{{ value_json.state_l1 }}"
    json_attributes_topic: "trigger"
    command_topic: "zigbee2mqtt/0x00124b00097331f3/l1/set"   
    optimistic: false
    retain: true

but got similar error…

Zigbee2MQTT:error 2020-11-05 23:09:37: Invalid JSON '{trigger: 10000}', skipping...

Have you tried this?

    payload_on: '{"trigger": 10000}'

With: payload_on: ‘{“trigger”: 10000}’, then I get this when switching on and off:

Zigbee2MQTT:debug 2020-11-06 21:02:49: Received MQTT message on 'zigbee2mqtt/0x00124b00097331f3/l1/set' with data '{“trigger”: 10000}'
Zigbee2MQTT:error 2020-11-06 21:02:49: Invalid JSON '{“trigger”: 10000}', skipping...
Zigbee2MQTT:info  2020-11-06 21:02:49: MQTT publish: topic 'zigbee2mqtt/0x00124b00097331f3', payload '{"linkquality":60,"state_l1":"OFF","state_l2":"OFF","state_l3":"OFF","state_l4":"OFF"}'
Zigbee2MQTT:debug 2020-11-06 21:02:49: Received MQTT message on 'zigbee2mqtt/0x00124b00097331f3/l1/set' with data 'OFF'

I’m not seeing the standard double-quotes I suggested but fancy double-quotes

Invalid JSON '{“trigger”: 10000}'
               ^       ^
               |       |
   These are not standard double-quotes

Don’t use these: “ ”
Use these: " "

2 Likes

Great, Thnx @123 finally got it working :grinning:

- platform: mqtt
    unique_id: test
    name: "Test Switch"
    state_topic: "zigbee2mqtt/0x00124b00097331f3"
    command_topic: "zigbee2mqtt/0x00124b00097331f3/l1/set"   
    availability_topic: "zigbee2mqtt/bridge/state"
    payload_off: "OFF"
    payload_on: '{"trigger": 10000}'
    value_template: "{{ value_json.state_l1 }}"
    optimistic: false
    retain: true
1 Like