How do I test a sunrise/sunset automation trigger

I am setting up a sunrise based automation

trigger:
  - platform: sun
    event: sunrise
    offset: 0

How do I trigger an event to test it? I have tried various things in the event developer tool, but cannot figure it out.

Interesting question…

I don’t have the answer, but you can try this:

Make an automation with this trigger and write the full event object to your log or a persistent notification. We can then see what it looks like in order to emulate it.

Not quite sure how to do that. Can you save me another hour of looking stuff up?

Go to Developer Tools > STATES, then open Set States. Enter sun.sun as the entity. Enter above_horizon or below_horizon. Then click SET STATE.

Sure thing. :slight_smile: I was on mobile, hence the brief response.

      - service: system_log.write
        data:
          message: "{{ trigger.event }}"
          level: debug
          logger: "homeassistant.components.automation"

Accompanying that, you’ll need this (depending on your default logger settings):

logger:
  default: warning  # my default is this
  logs:
    homeassistant.components.automation: debug

And/or (perhaps the quicker/easier option):

      - service: persistent_notification.create
        data:
          title: "Nick's Event Test"
          message: "{{ trigger.event }}"

Should have said that I tried that.

Thank you. I have done the persistent notification.

Now to wait for sunset …

1 Like

Not sure if this is your quandary, however can you not trigger the automation from Setting, Automations? picture below. I realize this does not address the source trigger, if that is issue. However, as you have done, sending debugging info out to home-assistant.log, at least you can see what is happening in the automation wiith well place debug log outputs.

IMHO, I think the Home Assistant automation and scripting are the biggest achilles heels of this system (maybe tied with ZHA zigbee). I really think the devs need to consider a new approach to scripting and automation in the coming year. What is there now is really lacking and BIG hindrance to regular folks doing more with HA.

Good hunting!

image

Yeah i do know how to use run, but that doesn’t test the trigger.

The usual case of a trigger that monitors a state is easy to test by changing the state in dev tools. (As suggested by @templeton_nash How do I test a sunrise/sunset automation trigger - #4 by templeton_nash ) but the sunrise/set trigger is not based on state, but on an event which i can’t find the docs for.