Please help with automation with if/else in service-data

Hmm, that’s odd then. I’m not familiar with device automations: I’d use something like:

action:
  - service: light.turn_on
    data_template:
      entity_id: light.tradfri_bulb_light
      brightness_pct: >
      # etc

I assume you have set up the sensor.period_of_day? (reference)