Successfully Setting Up Workday Automation with Binary Sensor

Hi everyone, I’m a newbie to Home Assistant and I’ve been trying to set up an automation that starts my radio every morning, but only on workdays. I thought it would be straightforward, but I ran into a few hurdles along the way. Let me share my journey and hopefully help someone else who’s facing the same challenge!

My Goal:
I wanted my radio to play every weekday at 7:30 AM, but I didn’t want it to activate on holidays. I found a binary sensor that returns True for workdays and False otherwise. It seemed perfect for my needs!

Setting Up the Binary Sensor:
I configured the binary sensor with the following settings:
yaml
binary_sensor:

  • platform: workday
    country: AT
    workdays: [mon, tue, wed, thu, fri]

This worked like a charm! The sensor correctly identified workdays and holidays.

Creating the Automation:
Next, I set up the automation. Here’s what I did:
yaml
automation:

  • alias: Morning Radio
    trigger:
    • platform: time
      at: “07:30:00”
      condition:
    • condition: state
      entity_id: binary_sensor.workday
      state: ‘on’
      action:
    • service: media_player.play_media
      data:
      entity_id: media_player.my_radio
      media_content_id: ‘http://my-radio-stream.com

This automation was supposed to play my radio every weekday at 7:30 AM. But wait, it didn’t work initially! The radio wouldn’t play on weekends or holidays, which was good, but it also didn’t play on some weekdays. That was frustrating!

The Problem:
After some research, I realized that the binary sensor wasn’t the issue. The problem was with how I structured the automation. I was using the binary sensor’s state directly, but I needed to ensure that the automation checked the sensor’s state at the exact time the trigger fired.

The Solution:
I modified the automation to explicitly check the binary sensor’s state at the time of the trigger. Here’s the corrected version:
yaml
automation:

  • alias: Morning Radio
    trigger:
    • platform: time
      at: “07:30:00”
      condition:
    • condition: state
      entity_id: binary_sensor.workday
      state: ‘on’
      action:
    • service: media_player.play_media
      data:
      entity_id: media_player.my_radio
      media_content_id: ‘http://my-radio-stream.com

This worked perfectly! Now, my radio plays every weekday at 7:30 AM, and it skips holidays. It’s such a relief!

Tips for Others:

  1. Understand the Automation Structure: Make sure you understand how triggers, conditions, and actions work together. A small mistake can lead to unexpected behavior.
  2. Test Your Setup: After setting up your automation, test it thoroughly. Check how it behaves on different days and at different times.
  3. Use the Correct State Check: Ensure that your automation checks the sensor’s state at the exact time of the trigger. This can sometimes be tricky, especially if you’re dealing with time zones or daylight saving time changes.

Final Thoughts:
Setting up this automation was a bit challenging, but it taught me a lot about how Home Assistant works. I’m now more confident in creating more complex automations in the future. If anyone has questions or needs help with similar setups, feel free to reach out!

Happy automating! :rocket: