Help with triggering an automation ONLY when date is changed in the state

I cant manage to find anywhere answer to what I am trying to do.
I have an event entity that give me a state of time and date as show below

I want to do trigger an automation only when the state is changing - which means that the date and time is changing.

I have tried to trigger the automation simply when any state is changing as shown below:

BUT, it becomes a problem because this entity even is part of a third party integration that sometimes I reload manually. even if I dont reload it manually, sometimes it becomes unavailable and then come back again. problem is that whenever this entity is reloaded it triggers the automation even though the event wasn’t actually manually triggered.

below I attached a screenshot to show that within the same Date and Time state there are 2 events triggered. 1 of them is when I simply reload the integration. however, the date and time is preserved and only changes when I actually trigger the intergration.

my question is : how I create a trigger that only triggered when the date and time in the state is changed becuase if I just leave all blank it triggers on reload of integration and restart of home assistant.

I hope I was clear with my question

Thank you for for you help! :slight_smile:

If you switch the trigger to edit it in yaml you can use the not_from and not_to configuration variables.

trigger:
  - platform: state
    entity_id: event.reserve_lr_auto_corner_wiz_activated
    not_from:
      - unknown
      - unavailable
    not_to:
      - unknown
      - unavailable
1 Like

Thank you for the quick reply.
I have tried it now but unfortunately it still gets triggered when I reload the integration.
Basically when integration reloaded it triggers the event but I want it to be triggered only when the date is changed. At least this is the only way I can think of to isolate the trigger to only when it is actually triggered (which at that point logs a new date and time)

A state_changed event has to be posted to the event bus for a State trigger to fire. Check the automation trace to see what state the event entity is changing from during what you consider to be inappropriate triggers.

hi thank you for the reply
I have checked the trace timeline as you suggested.
I get the same exact log with the only difference of the date and time
in 2 of these occasions I triggered the event manually which has changed the date in history and you can also see the color has changed. this indicates that there was manual activation which triggered the automation.
however on the next occasions I have simply reloaded the intergration. it has triggered the automation but as you can see the date in the history graph not changed (which shown also by the color of the event that stayed the same).

image

in the “Trace Timeline” it appears all the same , and just shows at what time the event was triggered regardless if it was manually triggered or triggered by reloading the integration (which is only triggers the event without changing the state by changing it to a different date and time)

Triggered by the state of event.reserve_lr_auto_corner_wiz_activated at October 23, 2023 at 15:21:53
Triggered by the state of event.reserve_lr_auto_corner_wiz_activated at October 23, 2023 at 15:23:01
Triggered by the state of event.reserve_lr_auto_corner_wiz_activated at October 23, 2023 at 15:24:04

Post the trace json from the failed run of the automation (From the Trace viewer, go to the top right and click the 3-dot expansion menu, then select “Download trace”. Copy/paste the contents of the json file).

Here it is, honestly it is a little more than I can handle (understanding it :slight_smile: )
The full automation and what it does is not ideal and not finished but it is not the problem here. the problem is the trigger :slight_smile:

{
  "trace": {
    "last_step": "action/6",
    "run_id": "046a229c5aa475f42cdbf2305cfeb3e1",
    "state": "stopped",
    "script_execution": "finished",
    "timestamp": {
      "start": "2023-10-23T13:44:07.523536+00:00",
      "finish": "2023-10-23T13:44:10.199255+00:00"
    },
    "domain": "automation",
    "item_id": "1697998340642",
    "trigger": "state of event.reserve_lr_auto_corner_wiz_activated",
    "trace": {
      "trigger/0": [
        {
          "path": "trigger/0",
          "timestamp": "2023-10-23T13:44:07.523626+00:00",
          "changed_variables": {
            "this": {
              "entity_id": "automation.reserve_lr_double_click_wiz_corner_lights",
              "state": "on",
              "attributes": {
                "id": "1697998340642",
                "last_triggered": "2023-10-23T13:24:37.716279+00:00",
                "mode": "single",
                "current": 0,
                "friendly_name": "Reserve LR double click wiz corner lights"
              },
              "last_changed": "2023-10-23T13:38:43.898604+00:00",
              "last_updated": "2023-10-23T13:38:43.898604+00:00",
              "context": {
                "id": "01HDEC4QHTDBWDTKMR5NGXZNTJ",
                "parent_id": null,
                "user_id": null
              }
            },
            "trigger": {
              "id": "0",
              "idx": "0",
              "alias": null,
              "platform": "state",
              "entity_id": "event.reserve_lr_auto_corner_wiz_activated",
              "from_state": {
                "entity_id": "event.reserve_lr_auto_corner_wiz_activated",
                "state": "2023-10-23T13:23:01.000+00:00",
                "attributes": {
                  "event_types": [
                    "activated"
                  ],
                  "event_type": "activated",
                  "friendly_name": "Reserve LR Auto corner wiz activated"
                },
                "last_changed": "2023-10-23T13:38:34.673696+00:00",
                "last_updated": "2023-10-23T13:38:34.673696+00:00",
                "context": {
                  "id": "01HDEC4EHHNWA3S55NFRWBJMGC",
                  "parent_id": null,
                  "user_id": null
                }
              },
              "to_state": {
                "entity_id": "event.reserve_lr_auto_corner_wiz_activated",
                "state": "unavailable",
                "attributes": {
                  "restored": true,
                  "event_types": [
                    "activated"
                  ],
                  "friendly_name": "Reserve LR Auto corner wiz activated",
                  "supported_features": 0
                },
                "last_changed": "2023-10-23T13:44:07.342624+00:00",
                "last_updated": "2023-10-23T13:44:07.342624+00:00",
                "context": {
                  "id": "01HDECEKDEWCQ7TPG9CMRVFVFQ",
                  "parent_id": null,
                  "user_id": null
                }
              },
              "for": null,
              "attribute": null,
              "description": "state of event.reserve_lr_auto_corner_wiz_activated"
            }
          }
        }
      ],
      "action/0": [
        {
          "path": "action/0",
          "timestamp": "2023-10-23T13:44:07.540970+00:00",
          "changed_variables": {
            "context": {
              "id": "01HDECEKK3F78P7PK2XX50NM2E",
              "parent_id": "01HDECEKDEWCQ7TPG9CMRVFVFQ",
              "user_id": null
            }
          },
          "result": {
            "params": {
              "domain": "light",
              "service": "toggle",
              "service_data": {
                "brightness_pct": 75,
                "entity_id": [
                  "light.wiz_corner_lights"
                ]
              },
              "target": {
                "entity_id": [
                  "light.wiz_corner_lights"
                ]
              }
            },
            "running_script": false
          }
        }
      ],
      "action/1": [
        {
          "path": "action/1",
          "timestamp": "2023-10-23T13:44:07.796997+00:00"
        }
      ],
      "action/2": [
        {
          "path": "action/2",
          "timestamp": "2023-10-23T13:44:07.797841+00:00",
          "result": {
            "delay": 1,
            "done": true
          }
        }
      ],
      "action/3": [
        {
          "path": "action/3",
          "timestamp": "2023-10-23T13:44:08.808456+00:00",
          "result": {
            "result": true
          }
        }
      ],
      "action/3/conditions/0": [
        {
          "path": "action/3/conditions/0",
          "timestamp": "2023-10-23T13:44:08.808582+00:00",
          "result": {
            "result": false
          }
        }
      ],
      "action/3/conditions/0/entity_id/0": [
        {
          "path": "action/3/conditions/0/entity_id/0",
          "timestamp": "2023-10-23T13:44:08.808609+00:00",
          "result": {
            "result": false,
            "state": "unavailable",
            "wanted_state": "off"
          }
        }
      ],
      "action/4": [
        {
          "path": "action/4",
          "timestamp": "2023-10-23T13:44:08.808682+00:00",
          "result": {
            "delay": 1,
            "done": true
          }
        }
      ],
      "action/5": [
        {
          "path": "action/5",
          "timestamp": "2023-10-23T13:44:09.809512+00:00"
        }
      ],
      "action/6": [
        {
          "path": "action/6",
          "timestamp": "2023-10-23T13:44:09.810149+00:00",
          "result": {
            "params": {
              "domain": "notify",
              "service": "mobile_app_pixel_8_pro",
              "service_data": {
                "message": "Test"
              },
              "target": {}
            },
            "running_script": false
          }
        }
      ]
    },
    "config": {
      "id": "1697998340642",
      "alias": "Reserve LR double click wiz corner lights",
      "description": "",
      "trigger": [
        {
          "platform": "state",
          "entity_id": "event.reserve_lr_auto_corner_wiz_activated",
          "not_from": [
            "unknown",
            "unavailable"
          ]
        }
      ],
      "condition": [],
      "action": [
        {
          "service": "light.toggle",
          "data": {
            "brightness_pct": 75
          },
          "target": {
            "entity_id": "light.wiz_corner_lights"
          },
          "enabled": true
        },
        {
          "type": "turn_off",
          "device_id": "5ec288417f1b8f52c78f97e532148444",
          "entity_id": "6bf0ea4b5a383224c7601e4ed6f1f007",
          "domain": "light"
        },
        {
          "delay": {
            "hours": 0,
            "minutes": 0,
            "seconds": 1,
            "milliseconds": 0
          }
        },
        {
          "condition": "not",
          "conditions": [
            {
              "condition": "state",
              "entity_id": "light.reserv",
              "state": "off"
            }
          ]
        },
        {
          "delay": {
            "hours": 0,
            "minutes": 0,
            "seconds": 1,
            "milliseconds": 0
          }
        },
        {
          "type": "turn_off",
          "device_id": "624f927b853e236f70eb6e714d7b73d9",
          "entity_id": "light.reserv",
          "domain": "light"
        },
        {
          "service": "notify.mobile_app_pixel_8_pro",
          "data": {
            "message": "Test"
          }
        }
      ],
      "mode": "single"
    },
    "blueprint_inputs": null,
    "context": {
      "id": "01HDECEKK3F78P7PK2XX50NM2E",
      "parent_id": "01HDECEKDEWCQ7TPG9CMRVFVFQ",
      "user_id": null
    }
  },
  "logbookEntries": [
    {
      "name": "Reserve LR double click wiz corner lights",
      "message": "triggered by state of event.reserve_lr_auto_corner_wiz_activated",
      "source": "state of event.reserve_lr_auto_corner_wiz_activated",
      "entity_id": "automation.reserve_lr_double_click_wiz_corner_lights",
      "context_id": "01HDECEKK3F78P7PK2XX50NM2E",
      "when": 1698068647.523729,
      "domain": "automation"
    },
    {
      "when": 1698068647.696157,
      "state": "off",
      "entity_id": "light.wiz_long_stand",
      "icon": "mdi:floor-lamp",
      "context_event_type": "automation_triggered",
      "context_domain": "automation",
      "context_name": "Reserve LR double click wiz corner lights",
      "context_message": "triggered by state of event.reserve_lr_auto_corner_wiz_activated",
      "context_source": "state of event.reserve_lr_auto_corner_wiz_activated",
      "context_entity_id": "automation.reserve_lr_double_click_wiz_corner_lights"
    },
    {
      "when": 1698068647.699458,
      "state": "off",
      "entity_id": "light.wiz_corner_lights",
      "icon": "mdi:lamps",
      "context_event_type": "automation_triggered",
      "context_domain": "automation",
      "context_name": "Reserve LR double click wiz corner lights",
      "context_message": "triggered by state of event.reserve_lr_auto_corner_wiz_activated",
      "context_source": "state of event.reserve_lr_auto_corner_wiz_activated",
      "context_entity_id": "automation.reserve_lr_double_click_wiz_corner_lights"
    },
    {
      "when": 1698068647.70274,
      "state": "off",
      "entity_id": "light.wiz_living_room_cupboard_kitchen",
      "icon": "mdi:lamp",
      "context_event_type": "automation_triggered",
      "context_domain": "automation",
      "context_name": "Reserve LR double click wiz corner lights",
      "context_message": "triggered by state of event.reserve_lr_auto_corner_wiz_activated",
      "context_source": "state of event.reserve_lr_auto_corner_wiz_activated",
      "context_entity_id": "automation.reserve_lr_double_click_wiz_corner_lights"
    },
    {
      "when": 1698068647.706185,
      "state": "off",
      "entity_id": "light.all_living_room_lights_helper",
      "icon": "mdi:lamps",
      "context_event_type": "automation_triggered",
      "context_domain": "automation",
      "context_name": "Reserve LR double click wiz corner lights",
      "context_message": "triggered by state of event.reserve_lr_auto_corner_wiz_activated",
      "context_source": "state of event.reserve_lr_auto_corner_wiz_activated",
      "context_entity_id": "automation.reserve_lr_double_click_wiz_corner_lights"
    },
    {
      "when": 1698068647.746038,
      "state": "off",
      "entity_id": "light.wiz_living_room_corner_tv",
      "icon": "mdi:lamp",
      "context_event_type": "automation_triggered",
      "context_domain": "automation",
      "context_name": "Reserve LR double click wiz corner lights",
      "context_message": "triggered by state of event.reserve_lr_auto_corner_wiz_activated",
      "context_source": "state of event.reserve_lr_auto_corner_wiz_activated",
      "context_entity_id": "automation.reserve_lr_double_click_wiz_corner_lights"
    },
    {
      "when": 1698068647.763638,
      "state": "off",
      "entity_id": "light.wiz_living_room_cupboard_window",
      "icon": "mdi:lamp",
      "context_event_type": "automation_triggered",
      "context_domain": "automation",
      "context_name": "Reserve LR double click wiz corner lights",
      "context_message": "triggered by state of event.reserve_lr_auto_corner_wiz_activated",
      "context_source": "state of event.reserve_lr_auto_corner_wiz_activated",
      "context_entity_id": "automation.reserve_lr_double_click_wiz_corner_lights"
    }
  ]
}

The automation triggered because the event entity’s state changed to “unavailable”, so you need to add not_to to the trigger:

trigger:
  - platform: state
    entity_id: event.reserve_lr_auto_corner_wiz_activated
    not_from:
      - unknown
      - unavailable
    not_to:
      - unknown
      - unavailable
1 Like

wohoooo! thank you! that did the trick! Now all works as intended! Thank you so much!! :smiley:
it now opens up a whole bunch of new possiblites for me now it works! thank you again!

EDIT : not sure if I should change the title of the topic becuase obviously it turned out to be a different approach and different source of the issue.