Automation does not work - wrong condition declaration

Dear All,
I am trying to write an automation. My intention is that:
on specific time, if IR trigger fires (I am using sonoff bridge flashed tasmota), HA will call ringtone on Xiaomi hub integrated on HA. My config below but seem wrong for it automation does not work
Can anyone help me to show what’s wrong with my code?

- alias: Barking high volume
  trigger:
    - platform: mqtt
      topic: tele/sonoffrf/RESULT
  condition:
    condition: and
    conditions:
      - condition: template
        value_template: "{{ trigger.payload_json.RfReceived.Data == '7F176A' }}"
      - condition: time
        after: '23:30:00'
        before: '05:30:00'
  action:
    service: xiaomi_aqara.play_ringtone
    data:
      gw_mac: XXXXXXXXXXXXXX
      ringtone_id: 8
      ringtone_vol: 60

You need two time conditions, with “or” between them.
Time can’t be both after 23:30 and before 05:30 at the same time.

1 Like

Surely this is a trigger? Not a condition.

Dear Olen,
Many thanks for your suggestion. What I need is let us fire between 23:30 today and 05:30 tomorrow.
I will try to correct it

Hi nickrout,
Many thanks for your comment.
Acctually, without “condition: time”, the automation work well, like this:

- alias: RM1 button A
  trigger:
    - platform: mqtt
      topic: tele/sonoffrf/RESULT
  condition:
    - condition: template
      value_template: "{{ trigger.payload_json.RfReceived.Data == '65F708' }}"
  action:
    - service: switch.turn_on
      entity_id: switch.dining_light
1 Like

You would need something like this:

  condition:
    condition: or
    conditions:
      - condition: time
        after: '23:30:00'
      - condition: time
        before: '05:30:00'

All conditions as “and” if you do not specify “or”.

Dear Olen,
Many thanks for your help.
However, I am confused: How to pu the rest condition:

    - condition: template
      value_template: "{{ trigger.payload_json.RfReceived.Data == '0620A9' }}" 
- alias: Barking high volume
  trigger:
    - platform: mqtt
      topic: tele/sonoffrf/RESULT
  condition:
    - condition: template
      value_template: "{{ trigger.payload_json.RfReceived.Data == '7F176A' }}"
    - condition: or
      conditions:
        - condition: time
          after: '23:30:00'
        - condition: time 
          before: '05:30:00'
  action:
    service: xiaomi_aqara.play_ringtone
    data:
      gw_mac: XXXXXXXXXXXXXX
      ringtone_id: 8
      ringtone_vol: 60

Dear mf_socialMarc :uk:
Many thanks for your help. Actually, I do not know these coding for I am amateur user. Just find, read and copy, paste and test.
I will try and let you know result.
Minh Chau

1 Like

Hi https://community.home-assistant.io/u/mf_social,
I tried your solution yesterday and it work!
Many thanks for your help!
Minh Chau

1 Like

Dear mf_social,
I am trying this as well but it does not work (Another automation, not the once you fixed)
My idea is that:
When the IR fires and then door sensor fires (both via Sonoff Bridge Tamota), then, home assistant will turn on a switch.
Note: door sensor has no state (such as opened or closed) information, just firing once door opens.
My code are below, can you help me once again?

- alias: something
  trigger:
    - platform: mqtt
      topic: tele/sonoffrf/RESULT
  condition:
    - condition: and
      conditions:
        - condition: template
          value_template: "{{ trigger.payload_json.RfReceived.Data == '7F176A' }}"
        - condition: template
          value_template: "{{ trigger.payload_json.RfReceived.Data == '4D968E' }}"
  action:
   - service: switch.turn_on
     entity_id: switch.center_light

Again, this is a condition that cannot be fulfilled.
You will not receive both of these values in the same packet.
You probably need to make some template sensors based on the mqtt packets, and check the state of the sensors instead of the mqtt payload directly.

2 Likes