Help with a automation working with app reply

Hello,

I have the idea to create an automation that, if I leave my work, I will receive a push notification in the app that I am leaving work. The automation should ask if I want to start heating at home.

My first try with “yes and no” works, but I wanted to add a question about the room which I want to heat up. So I added another question with three possibilities.

At the moment, the problem is that I will receive any question. But if I choose a room, for example, the living room, nothing will happen. No push that heating is started and no error in logs…

Here is the code

alias: 01_Climate_go_home
description: Ask to start heating if leaving work
trigger:
  - platform: zone
    entity_id: device_tracker.mobile
    zone: zone.work
    event: leave
condition: []
action:
  - alias: Set up variables for the actions
    variables:
      action_heat: "{{ 'HEAT_' ~ context.id }}"
      action_nothing: "{{ 'NOTHING_' ~ context.id }}"
  - alias: Ask to start heating
    service: notify.mobile_app_mobile
    data:
      message: >-
        You've just left work. Would you like to switch on the heating?
      data:
        actions:
          - action: "{{ action_heat }}"
            title: heat
          - action: "{{ action_nothing }}"
            title: dont heat
  - alias: Wait for a response
    wait_for_trigger:
      - platform: event
        event_type: mobile_app_notification_action
        event_data:
          action: "{{ action_heat }}"
      - platform: event
        event_type: mobile_app_notification_action
        event_data:
          action: "{{ action_nothing }}"
  - alias: Set up variables for the actions
    variables:
      action_select_room: "{{ 'SELECT_ROOM_' ~ context.id }}"
  - alias: Perform the action or select room
    choose:
      - conditions: "{{ wait.trigger.event.data.action == action_heat }}"
        sequence:
          - service: notify.mobile_app_mobile
            data:
              message: In which room would you like to heat?
              data:
                actions:
                  - action: "{{ action_select_room }}"
                    title: living_room
                  - action: "{{ action_select_room }}"
                    title: dining_room
                  - action: "{{ action_select_room }}"
                    title: bedroom
          - wait_for_trigger:
              - platform: event
                event_type: mobile_app_notification_action
                event_data:
                  action: "{{ action_select_room }}"
          - choose:
              - conditions: "{{ wait.trigger.event.data.action == 'living_room' }}"
                sequence:
                  - service: climate.set_temperature
                    data:
                      temperature: 22
                    target:
                      device_id: ID
                  - device_id: ID
                    domain: climate
                    entity_id: ID
                    type: set_hvac_mode
                    hvac_mode: heat
                  - service: notify.mobile_app_mobile
                    data:
                      message: Heating in the living_room is switched on.
              - conditions: "{{ wait.trigger.event.data.action == 'dining_room' }}"
                sequence:
                  - service: climate.set_temperature
                    data:
                      temperature: 22
                    target:
                      device_id: ID
                  - device_id: ID
                    domain: climate
                    entity_id: ID
                    type: set_hvac_mode
                    hvac_mode: heat
                  - service: notify.mobile_app_mobile
                    data:
                      message: Heating in the dining_room is switched on.
              - conditions: "{{ wait.trigger.event.data.action == 'bedroom' }}"
                sequence:
                  - service: climate.set_temperature
                    data:
                      temperature: 22
                    target:
                      device_id: ID
                  - device_id: ID
                    domain: climate
                    entity_id: ID
                    type: set_hvac_mode
                    hvac_mode: heat
                  - service: notify.mobile_app_mobile
                    data:
                      message: Heating in the bedroom is switched on.
              - conditions: "{{ wait.trigger.event.data.action == action_nothing }}"
                sequence:
                  - service: notify.mobile_app_mobile
                    data:
                      message: Okee, I'm not switching on the heating :)
    default: []
mode: single

I hope anyone has an Idea…

I have an idea, but what does your trace show? Please post it here.

Thanks for reply.

Some screenshots, full trace is below :slight_smile:

It always seems to go to “other”, even though I make a selection.

Here is the full log from trace:

{
  "trace": {
    "last_step": "action/4/choose/0/sequence/2/choose/3/conditions/0",
    "run_id": "d0f3fd6134c0ce87360a217410e3e39d",
    "state": "stopped",
    "script_execution": "finished",
    "timestamp": {
      "start": "2023-12-04T12:14:50.127219+00:00",
      "finish": "2023-12-04T12:14:58.641011+00:00"
    },
    "domain": "automation",
    "item_id": "1701690308118",
    "trigger": null,
    "trace": {
      "trigger": [
        {
          "path": "trigger",
          "timestamp": "2023-12-04T12:14:50.127503+00:00",
          "changed_variables": {
            "this": {
              "entity_id": "automation.01_climate_go_home_user_test",
              "state": "on",
              "attributes": {
                "id": "1701690308118",
                "last_triggered": "2023-12-04T12:13:48.167879+00:00",
                "mode": "single",
                "current": 0,
                "friendly_name": "01_Climate_go_home_André"
              },
              "last_changed": "2023-12-04T12:14:47.738074+00:00",
              "last_updated": "2023-12-04T12:14:47.738074+00:00",
              "context": {
                "id": "01HGTC17DT5VWA77TV6NZZ4TS2",
                "parent_id": null,
                "user_id": null
              }
            },
            "trigger": {
              "platform": null
            }
          }
        }
      ],
      "action/0": [
        {
          "path": "action/0",
          "timestamp": "2023-12-04T12:14:50.132038+00:00",
          "changed_variables": {
            "context": {
              "id": "01HGTC19RF1EKR0EGXSY2TJ32E",
              "parent_id": "01HGTC19RE6J8Z0N00E7DKJY11",
              "user_id": null
            }
          }
        }
      ],
      "action/1": [
        {
          "path": "action/1",
          "timestamp": "2023-12-04T12:14:50.133911+00:00",
          "changed_variables": {
            "action_heat": "HEAT_01HGTC19RF1EKR0EGXSY2TJ32E",
            "action_nothing": "NOTHING_01HGTC19RF1EKR0EGXSY2TJ32E"
          },
          "result": {
            "params": {
              "domain": "notify",
              "service": "mobile_app_iphone_von_user",
              "service_data": {
                "message": "Du hast soeben die Arbeit verlassen. Möchtest du die Heizung einschalten?",
                "data": {
                  "actions": [
                    {
                      "action": "HEAT_01HGTC19RF1EKR0EGXSY2TJ32E",
                      "title": "Heizen"
                    },
                    {
                      "action": "NOTHING_01HGTC19RF1EKR0EGXSY2TJ32E",
                      "title": "Nicht heizen"
                    }
                  ]
                }
              },
              "target": {}
            },
            "running_script": false
          }
        }
      ],
      "action/2": [
        {
          "path": "action/2",
          "timestamp": "2023-12-04T12:14:50.610996+00:00",
          "result": {
            "wait": {
              "remaining": null,
              "trigger": {
                "id": "0",
                "idx": "0",
                "alias": null,
                "platform": "event",
                "event": {
                  "event_type": "mobile_app_notification_action",
                  "data": {
                    "action": "HEAT_01HGTC19RF1EKR0EGXSY2TJ32E"
                  },
                  "origin": "REMOTE",
                  "time_fired": "2023-12-04T12:14:55.616229+00:00",
                  "context": {
                    "id": "01HGTC1F40V8ARX3GG8VENFTG5",
                    "parent_id": null,
                    "user_id": "9c22537926224dd886259ad993ac5a20"
                  }
                },
                "description": "event 'mobile_app_notification_action'"
              }
            }
          }
        }
      ],
      "action/3": [
        {
          "path": "action/3",
          "timestamp": "2023-12-04T12:14:55.636334+00:00",
          "changed_variables": {
            "wait": {
              "remaining": null,
              "trigger": {
                "id": "0",
                "idx": "0",
                "alias": null,
                "platform": "event",
                "event": {
                  "event_type": "mobile_app_notification_action",
                  "data": {
                    "action": "HEAT_01HGTC19RF1EKR0EGXSY2TJ32E"
                  },
                  "origin": "REMOTE",
                  "time_fired": "2023-12-04T12:14:55.616229+00:00",
                  "context": {
                    "id": "01HGTC1F40V8ARX3GG8VENFTG5",
                    "parent_id": null,
                    "user_id": "9c22537926224dd886259ad993ac5a20"
                  }
                },
                "description": "event 'mobile_app_notification_action'"
              }
            }
          }
        }
      ],
      "action/4": [
        {
          "path": "action/4",
          "timestamp": "2023-12-04T12:14:55.638188+00:00",
          "changed_variables": {
            "action_select_room": "SELECT_ROOM_01HGTC19RF1EKR0EGXSY2TJ32E"
          },
          "result": {
            "choice": 0
          }
        }
      ],
      "action/4/choose/0": [
        {
          "path": "action/4/choose/0",
          "timestamp": "2023-12-04T12:14:55.640180+00:00",
          "result": {
            "result": true
          }
        }
      ],
      "action/4/choose/0/conditions/0": [
        {
          "path": "action/4/choose/0/conditions/0",
          "timestamp": "2023-12-04T12:14:55.640342+00:00",
          "result": {
            "result": true,
            "entities": []
          }
        }
      ],
      "action/4/choose/0/sequence/0": [
        {
          "path": "action/4/choose/0/sequence/0",
          "timestamp": "2023-12-04T12:14:55.653252+00:00",
          "result": {
            "params": {
              "domain": "notify",
              "service": "mobile_app_iphone_von_user",
              "service_data": {
                "message": "In welchem Raum möchtest du heizen?",
                "data": {
                  "actions": [
                    {
                      "action": "SELECT_ROOM_01HGTC19RF1EKR0EGXSY2TJ32E",
                      "title": "Wohnzimmer"
                    },
                    {
                      "action": "SELECT_ROOM_01HGTC19RF1EKR0EGXSY2TJ32E",
                      "title": "Esszimmer"
                    },
                    {
                      "action": "SELECT_ROOM_01HGTC19RF1EKR0EGXSY2TJ32E",
                      "title": "Schlafzimmer"
                    }
                  ]
                }
              },
              "target": {}
            },
            "running_script": false
          }
        }
      ],
      "action/4/choose/0/sequence/1": [
        {
          "path": "action/4/choose/0/sequence/1",
          "timestamp": "2023-12-04T12:14:56.021166+00:00",
          "result": {
            "wait": {
              "remaining": null,
              "trigger": {
                "id": "0",
                "idx": "0",
                "alias": null,
                "platform": "event",
                "event": {
                  "event_type": "mobile_app_notification_action",
                  "data": {
                    "action": "SELECT_ROOM_01HGTC19RF1EKR0EGXSY2TJ32E"
                  },
                  "origin": "REMOTE",
                  "time_fired": "2023-12-04T12:14:58.619381+00:00",
                  "context": {
                    "id": "01HGTC1J1V5S5DVVFG1TVV6FYR",
                    "parent_id": null,
                    "user_id": "9c22537926224dd886259ad993ac5a20"
                  }
                },
                "description": "event 'mobile_app_notification_action'"
              }
            }
          }
        }
      ],
      "action/4/choose/0/sequence/2": [
        {
          "path": "action/4/choose/0/sequence/2",
          "timestamp": "2023-12-04T12:14:58.630280+00:00",
          "changed_variables": {
            "wait": {
              "remaining": null,
              "trigger": {
                "id": "0",
                "idx": "0",
                "alias": null,
                "platform": "event",
                "event": {
                  "event_type": "mobile_app_notification_action",
                  "data": {
                    "action": "SELECT_ROOM_01HGTC19RF1EKR0EGXSY2TJ32E"
                  },
                  "origin": "REMOTE",
                  "time_fired": "2023-12-04T12:14:58.619381+00:00",
                  "context": {
                    "id": "01HGTC1J1V5S5DVVFG1TVV6FYR",
                    "parent_id": null,
                    "user_id": "9c22537926224dd886259ad993ac5a20"
                  }
                },
                "description": "event 'mobile_app_notification_action'"
              }
            }
          }
        }
      ],
      "action/4/choose/0/sequence/2/choose/0": [
        {
          "path": "action/4/choose/0/sequence/2/choose/0",
          "timestamp": "2023-12-04T12:14:58.631814+00:00",
          "result": {
            "result": false
          }
        }
      ],
      "action/4/choose/0/sequence/2/choose/0/conditions/0": [
        {
          "path": "action/4/choose/0/sequence/2/choose/0/conditions/0",
          "timestamp": "2023-12-04T12:14:58.631932+00:00",
          "result": {
            "result": false,
            "entities": []
          }
        }
      ],
      "action/4/choose/0/sequence/2/choose/1": [
        {
          "path": "action/4/choose/0/sequence/2/choose/1",
          "timestamp": "2023-12-04T12:14:58.632735+00:00",
          "result": {
            "result": false
          }
        }
      ],
      "action/4/choose/0/sequence/2/choose/1/conditions/0": [
        {
          "path": "action/4/choose/0/sequence/2/choose/1/conditions/0",
          "timestamp": "2023-12-04T12:14:58.632855+00:00",
          "result": {
            "result": false,
            "entities": []
          }
        }
      ],
      "action/4/choose/0/sequence/2/choose/2": [
        {
          "path": "action/4/choose/0/sequence/2/choose/2",
          "timestamp": "2023-12-04T12:14:58.633556+00:00",
          "result": {
            "result": false
          }
        }
      ],
      "action/4/choose/0/sequence/2/choose/2/conditions/0": [
        {
          "path": "action/4/choose/0/sequence/2/choose/2/conditions/0",
          "timestamp": "2023-12-04T12:14:58.633673+00:00",
          "result": {
            "result": false,
            "entities": []
          }
        }
      ],
      "action/4/choose/0/sequence/2/choose/3": [
        {
          "path": "action/4/choose/0/sequence/2/choose/3",
          "timestamp": "2023-12-04T12:14:58.634306+00:00",
          "result": {
            "result": false
          }
        }
      ],
      "action/4/choose/0/sequence/2/choose/3/conditions/0": [
        {
          "path": "action/4/choose/0/sequence/2/choose/3/conditions/0",
          "timestamp": "2023-12-04T12:14:58.634420+00:00",
          "result": {
            "result": false,
            "entities": []
          }
        }
      ]
    },
    "config": {
      "id": "1701690308118",
      "alias": "01_Climate_go_home_André",
      "description": "Ask to start heating if leaving work",
      "trigger": [
        {
          "platform": "zone",
          "entity_id": "device_tracker.iphone_von_user",
          "zone": "zone.scheidt_bachmann_gmbh",
          "event": "leave"
        }
      ],
      "condition": [],
      "action": [
        {
          "alias": "Set up variables for the actions",
          "variables": {
            "action_heat": "{{ 'HEAT_' ~ context.id }}",
            "action_nothing": "{{ 'NOTHING_' ~ context.id }}"
          }
        },
        {
          "alias": "Ask to start heating",
          "service": "notify.mobile_app_iphone_von_user",
          "data": {
            "message": "Du hast soeben die Arbeit verlassen. Möchtest du die Heizung einschalten?",
            "data": {
              "actions": [
                {
                  "action": "{{ action_heat }}",
                  "title": "Heizen"
                },
                {
                  "action": "{{ action_nothing }}",
                  "title": "Nicht heizen"
                }
              ]
            }
          }
        },
        {
          "alias": "Wait for a response",
          "wait_for_trigger": [
            {
              "platform": "event",
              "event_type": "mobile_app_notification_action",
              "event_data": {
                "action": "{{ action_heat }}"
              }
            },
            {
              "platform": "event",
              "event_type": "mobile_app_notification_action",
              "event_data": {
                "action": "{{ action_nothing }}"
              }
            }
          ]
        },
        {
          "alias": "Set up variables for the actions",
          "variables": {
            "action_select_room": "{{ 'SELECT_ROOM_' ~ context.id }}"
          }
        },
        {
          "alias": "Perform the action or select room",
          "choose": [
            {
              "conditions": "{{ wait.trigger.event.data.action == action_heat }}",
              "sequence": [
                {
                  "service": "notify.mobile_app_iphone_von_user",
                  "data": {
                    "message": "In welchem Raum möchtest du heizen?",
                    "data": {
                      "actions": [
                        {
                          "action": "{{ action_select_room }}",
                          "title": "Wohnzimmer"
                        },
                        {
                          "action": "{{ action_select_room }}",
                          "title": "Esszimmer"
                        },
                        {
                          "action": "{{ action_select_room }}",
                          "title": "Schlafzimmer"
                        }
                      ]
                    }
                  }
                },
                {
                  "wait_for_trigger": [
                    {
                      "platform": "event",
                      "event_type": "mobile_app_notification_action",
                      "event_data": {
                        "action": "{{ action_select_room }}"
                      }
                    }
                  ]
                },
                {
                  "choose": [
                    {
                      "conditions": "{{ wait.trigger.event.data.action == '01HGTBZMV2K7QNJ3YBXZV9BTVN' }}",
                      "sequence": [
                        {
                          "service": "climate.set_temperature",
                          "data": {
                            "temperature": 22
                          },
                          "target": {
                            "device_id": "0e789c51ff873be3afffb246e71f638e"
                          }
                        },
                        {
                          "device_id": "0e789c51ff873be3afffb246e71f638e",
                          "domain": "climate",
                          "entity_id": "8aeec6d2a8a0cd6d665f1ddd08f0b566",
                          "type": "set_hvac_mode",
                          "hvac_mode": "heat"
                        },
                        {
                          "service": "notify.mobile_app_iphone_von_user",
                          "data": {
                            "message": "Heizung im Wohnzimmer wird eingeschaltet."
                          }
                        }
                      ]
                    },
                    {
                      "conditions": "{{ wait.trigger.event.data.action == 'Esszimmer' }}",
                      "sequence": [
                        {
                          "service": "climate.set_temperature",
                          "data": {
                            "temperature": 22
                          },
                          "target": {
                            "device_id": "d4788650c286a01fb03c10fc9f9aeca9"
                          }
                        },
                        {
                          "device_id": "d4788650c286a01fb03c10fc9f9aeca9",
                          "domain": "climate",
                          "entity_id": "e7368d7ee15bd2b462c3fd95c08289de",
                          "type": "set_hvac_mode",
                          "hvac_mode": "heat"
                        },
                        {
                          "service": "notify.mobile_app_iphone_von_user",
                          "data": {
                            "message": "Heizung im Esszimmer wird eingeschaltet."
                          }
                        }
                      ]
                    },
                    {
                      "conditions": "{{ wait.trigger.event.data.action == 'Schlafzimmer' }}",
                      "sequence": [
                        {
                          "service": "climate.set_temperature",
                          "data": {
                            "temperature": 22
                          },
                          "target": {
                            "device_id": "d4788650c286a01fb03c10fc9f9aeca9"
                          }
                        },
                        {
                          "device_id": "d4788650c286a01fb03c10fc9f9aeca9",
                          "domain": "climate",
                          "entity_id": "e7368d7ee15bd2b462c3fd95c08289de",
                          "type": "set_hvac_mode",
                          "hvac_mode": "heat"
                        },
                        {
                          "service": "notify.mobile_app_iphone_von_user",
                          "data": {
                            "message": "Heizung im Schlafzimmer wird eingeschaltet."
                          }
                        }
                      ]
                    },
                    {
                      "conditions": "{{ wait.trigger.event.data.action == action_nothing }}",
                      "sequence": [
                        {
                          "service": "notify.mobile_app_iphone_von_user",
                          "data": {
                            "message": "Okee, ich schalte die Heizung nicht ein :)"
                          }
                        }
                      ]
                    }
                  ]
                }
              ]
            }
          ],
          "default": []
        }
      ],
      "mode": "single"
    },
    "blueprint_inputs": null,
    "context": {
      "id": "01HGTC19RF1EKR0EGXSY2TJ32E",
      "parent_id": "01HGTC19RE6J8Z0N00E7DKJY11",
      "user_id": null
    }
  },
  "logbookEntries": [
    {
      "name": "01_Climate_go_home_André",
      "message": "triggered",
      "source": null,
      "entity_id": "automation.01_climate_go_home_user_test",
      "context_id": "01HGTC19RF1EKR0EGXSY2TJ32E",
      "when": 1701692090.12771,
      "domain": "automation"
    }
  ]
}

It’s because your templates are incorrect and the setup for selecting a room is not correct either.

Change this portion of your automation:


  - alias: Set up variables for the actions
    variables:
      actions:
      - action: SELECT_LIVING_ROOM_{{ context.id }}
        title: living_room
      - action: SELECT_DINING_ROOM_{{ context.id }}
        title: dining_room
      - action: SELECT_BEDROOM_{{ context.id }}
        title: bedroom
  - alias: Perform the action or select room
    choose:
      - conditions: "{{ wait.trigger.event.data.action == action_heat }}"
        sequence:
          - service: notify.mobile_app_mobile
            data:
              message: In which room would you like to heat?
              data:
                actions: "{{ actions }}"
          - wait_for_trigger:
              - platform: event
                event_type: mobile_app_notification_action
                event_data:
                  action: "{{ actions[0].action }}"
              - platform: event
                event_type: mobile_app_notification_action
                event_data:
                  action: "{{ actions[1].action }}"
              - platform: event
                event_type: mobile_app_notification_action
                event_data:
                  action: "{{ actions[2].action }}"

Then your chooses will be:

              - conditions: "{{ wait.trigger.event.data.action == actions[0].action }}"
              - conditions: "{{ wait.trigger.event.data.action == actions[1].action }}"
              - conditions: "{{ wait.trigger.event.data.action == actions[2].action }}"
1 Like

Thank you, worked :slight_smile:

1 Like