Message malformed: extra keys not allowed @ data['sensor']

Hi, this is my script and i am getting this error “Message malformed: extra keys not allowed @ data[‘sensor’]” when trying to save it. Here is the script.

alias: Athan Automation
sensor:

  • platform: rest
    name: “Prayer Times”
    json_attributes:

    • data
      resource: “latitude=-33.83853661687818&longitude=150.9857852420184&method=0”
      value_template: ‘{{ value_json[“data”][“meta”][“method”][“name”].title() }}’
      scan_interval: 86400
  • platform: template
    sensors:
    fajr:
    friendly_name: ‘Fajr Prayer Time’
    value_template: ‘{{ states.sensor.prayer_times.attributes.data.timings[“Fajr”] | timestamp_custom("%H:%M") }}’
    dhuhr:
    friendly_name: ‘Dhuhr Prayer Time’
    value_template: ‘{{ states.sensor.prayer_times.attributes.data.timings[“Dhuhr”] | timestamp_custom("%H:%M") }}’
    asr:
    friendly_name: ‘Asr Prayer Time’
    value_template: ‘{{ states.sensor.prayer_times.attributes.data.timings[“Asr”] | timestamp_custom("%H:%M") }}’
    magrib:
    friendly_name: ‘Magrib Prayer Time’
    value_template: ‘{{ states.sensor.prayer_times.attributes.data.timings[“Maghrib”] | timestamp_custom("%H:%M") }}’
    isha:
    friendly_name: ‘Isha Prayer Time’
    value_template: ‘{{ states.sensor.prayer_times.attributes.data.timings[“Isha”] | timestamp_custom("%H:%M") }}’

automation:

  • alias: “Fajr Athan”
    initial_state: true
    hide_entity: true
    trigger:

    • condition: template
      value_template: ‘{{ states.sensor.time.state == states(“sensor.fajr”) }}’
      action:
    • service: media_player.volume_set
      data_template:
      entity_id: media_player.living_room_speaker
      volume_level: 0.75
    • service: media_player.play_media
      data:
      entity_id: media_player.living_room_speaker
      media_content_id:
      media_content_type: audio/mp3
  • alias: “Athan”
    initial_state: true
    hide_entity: true
    trigger:

    • platform: template
      value_template: ‘{{ states.sensor.time.state == states(“sensor.dhuhr”) }}’
    • platform: template
      value_template: ‘{{ states.sensor.time.state == states(“sensor.asr”) }}’
    • platform: template
      value_template: ‘{{ states.sensor.time.state == states(“sensor.maghrib”) }}’
    • platform: template
      value_template: ‘{{ states.sensor.time.state == states(“sensor.isha”) }}’
      action:
    • service: media_player.volume_set
      data_template:
      entity_id: media_player.living_room_speaker
      volume_level: 0.75
    • service: media_player.play_media
      data:
      entity_id: media_player.living_room_speaker
      media_content_id:
      media_content_type: audio/mp3

Please help. thanks

Please format your code., otherwise it’s unreadable and people will have a hard time helping you.

See:

Wherever you got all of that code, it’s needlessly complicated and outdated. It’s also missing important information (like a URL for the REST sensor and content for the media_player).

Use the Islamic Prayer Time integration with an automation like this:


- id: 'athan_automation'
  alias: Athan Automation
  trigger:
  - platform: time
    at:
    - sensor.fajr_prayer
    - sensor.dhuhr_prayer
    - sensor.asr_prayer
    - sensor.maghrib_prayer
    - sensor.isha_prayer
  action:
  - service: media_player.volume_set
    target:
      entity_id: media_player.living_room_speaker
    data:
      volume_level: 0.75
  - service: media_player.play_media
    target:
      entity_id: media_player.living_room_speaker
    data:
      media_content_id: https://www.islamcan.com/audio/adhan/azan1.mp3
      media_content_type: music

Thank you for replying. When i was submitting this query, it gave me an error, saying as I am a new member, I cant post more than 2 URLs, that’s why I removed URL for REST sensor and media_player.

I copied this code from the internet. I am a newbie in this automation world and have no coding experience. Apart from being complicated, do you think this code cant work?

Sorry but that code is outdated, needlessly complicated, and I won’t waste time correcting it. Either use the modern equivalent I suggested or wait for someone else to help you sort out that ancient mess. Good luck.

Thank you. I am using your automation, thanks a lot.

Have you found Islamic Prayer Time integration accurate? I am seeing an 18-20 minutes difference. Is there any way I can set a location (city) for this integration?

I don’t use it so I can’t comment on its accuracy.

You can configure the integration to use different calculation methods. I don’t know if changing the method helps to eliminate the 18-20 minutes difference.

If that doesn’t work, you can manually offset each prayer time, by whatever amount you want, using the technique I offered another user who wanted to add 5 minutes (300 seconds) to each one:

1 Like