avraham / hass_radarr_sonarr_search_by_voice

Add movies to radarr by voice
GNU General Public License v3.0
46 stars 8 forks source link

Remove reliance on legacy API key #3

Closed sinker1345 closed 4 years ago

sinker1345 commented 5 years ago

Can we please update this script to remove the reliance on the legacy API key? It is supposed to be deprecated soon and I currently only need to keep it active because of this integration.

avraham commented 5 years ago

I will look into that.

sinker1345 commented 5 years ago

Thank you for taking the time, I don't know python but if you need help testing or anything let me know

avraham commented 5 years ago

I updated the code and it now supports long-lived tokens. I've tested it and it works locally.

It looks like calling scripts with IFTTT using long-lived tokens is not as straight forward as with legacy API. It's possible, but I don't have much spare time at the moment to give an exmple.

If you have time and can provide an example I would greatly appreciate it.

sinker1345 commented 5 years ago

I may not be able to update this and mess with it any time soon but as soon as I am able to play with it I will provide an example

sinker1345 commented 4 years ago

OK so I sat down and worked through this.

You do not need to send the header through IFTTT. I use the IFTTT webhook recieved trigger. I have more then one of these so I have to make conditions to ensure only one runs at a time (as they use the same webhook). I have included an example code below.

- alias: "IFTTT" 
    trigger:
      - platform: event
        event_type: ifttt_webhook_received
        event_data:
          action: call_service
    condition:
      condition: and
      conditions:
        - condition: template
          value_template: "{{ trigger.event.data.service != 'script.download_movie' }}"
    action:
      - service_template: '{{ trigger.event.data.service }}'
        data_template: 
          entity_id: '{{ trigger.event.data.entity_id }}'

  - alias: "IFTTTmovie" 
    trigger:
      - platform: event
        event_type: ifttt_webhook_received
        event_data:
          action: call_service
    condition:
      condition: and
      conditions:
        - condition: template
          value_template: "{{ trigger.event.data.service == 'script.download_movie' }}"
    action:
      - service_template: '{{ trigger.event.data.service }}'
        data_template: 
          movie: '{{ trigger.event.data.movie }}'

on IFTTT my webhook has a link in the following format

https://HA_WEB_ADDRESS/api/webhook/IFTTT_WEEBHOOK_ID

the method is still POST and content type is still application/json

The body has changed to

{ "action": "call_service", "service": "script.download_movie", "movie": "{{TextField}}"}

using this method I am able to call the downloader script and get a response as well as call other applets that do not need the addidional movie: field in HA without error

Sorry for the long delay on working through this.

avraham commented 4 years ago

Thank you for taking the time to provide a detailed example. This actually helped me to update my setup, and I'm sure it will help others. I'll link your post in the project description as a reference to how integrate this with IFTTT.

colethegamer123 commented 3 years ago

Im nearly done, I set everything, one by one everything working except the the movie name. If I fix the movie name in the shell script I can use with IFTTT and downloads it, but if I write back $1, It does not recognize movie name, and drops error.

avraham commented 3 years ago

Im nearly done, I set everything, one by one everything working except the the movie name. If I fix the movie name in the shell script I can use with IFTTT and downloads it, but if I write back $1, It does not recognize movie name, and drops error.

Can you share your automation code and IFTTT setup. Make sure to delete any sensible information like your HA_WEB_ADDRESS and IFTTT_WEEBHOOK_ID

colethegamer123 commented 3 years ago

Hallo my friend,

I was able to make it work from HA Terminal, but as soon I run it from HA with automation, its not working. The parameter movie name and 0 is failing because of qoutes im nearly sure.

Here is the issue I opend: https://community.home-assistant.io/t/quotes-ssh-and-docker-shell-commands/234935

Thank you mate :)