Mycroft Community Forum

Make a web request

Skill name: Make a web request

User story:

_As a (type of user) I want this Skill to be able to make simpme web requests so that I can integrate it with a tool I use for home automation.

What third party services, data sets or platforms will the Skill interact with? It literally just needs to make a web request. For my purposes, it just needs to run curl and the url on the command line and it will make the request.

Are there similar Mycroft Skills already? Not that I know off.

See https://github.com/MycroftAI/mycroft-skills for a list. If so, how could they be combined?

What will the user Speak to trigger the Skill?
The user will be able to define names to each web request and set up a custom trigger.

What phrases will Mycroft Speak?
Just a confirmation

What Skill Settings will this Skill need to store?
Just the different requests and the trigger word.
See https://mycroft.ai/documentation/skills/skill-settings/ for more information

Other comments?
Not really. I just think this would be a powerful, yet simple to implement skill.
Put any other comments you think are relevant in here

Thanks!

If I understand correctly you to perform http-requests to a web-application by a Mycroft skill? For that you may want to have a look at Requests python library. Otherwise you need to be more specific, do you have a example requests? what is your “home automation tool”?

Hello there
I’ve the same request, so I’ll try to clarify:
I have a smart switch that turns the light on by making a GET request to

http://192.168.1.123/relay0?cmd=on

Having mycroft react to “Hey Mycroft! Turn Light On” by wgetting the above URL would be pretty sweet (of course, the basic idea here is to make keywords/URLs customizable)
Thanks!

URL looks familiar, is this for a Shelly device?
Python code with requests library could look like following:

import requests
response = requests.get('http://192.168.1.123/relay0', params={'cmd': 'on'})

Thanks @Dominik
yep, you guessed right :slight_smile:
Thanks for the code
I think it would be useful for anyone to have it inserted in the marketplace as a generic solution, since many IoT devices (Tasmota being the most used) accept HTTP commands for simple tasks (On/Off) without requiring an home automation backend.
Thanks!

Hey, you piqued my interest and I had a little free time, so:

Currently only space for a single parameter, but this should be sufficient for Dominiks example above.

1 Like

Hey @gez-mycroft, thanks!
I’ve cloned the repo in to /skills, and edited the
/mycroft-core/skills/make-get-request-skill.krisgesling/settingsmeta.yml

it now looks like this:

skillMetadata:
  sections:
    - name: Trigger
      fields:
        - name: trigger_phrase
          type: text
          label: Trigger phrase
          value: "lights on"
          placeholder: this should not include the wake word
        - name: response_on_success
          type: text
          label: Response on success
          value: "as you command"
        - name: response_on_failure
          type: text
          label: Response on failure
          value: "I can't sir"
[...]

I have also restarted mycroft with:
./start-mycroft.sh restart all

giving the command :skills in the CLI correctly lists make-get-request-skill.krisgesling among the installed skills.
but when I say “Hey Mycroft! … lights on”, Mycroft responds with :

          lights on                                DEBUG output
          >> I don't know what that means.  

Is there anything else I need to do?
Again, thanks for your support!

The relevant part for this to trigger is @intent_handler(‘make.request.intent’), thus saying “Test this thing for me”. This is just a framework to be fleshed out.

Bullshit, haven’t recognized update_intent_file

can you nano in make.request.intent and post the content?
(i expect a newline problem)

Thanks @SGee, here is the nano of make.request.intent

test this thing for me

I don’t think it’s very evident from the code above, but there is a newline after “test this thing for me”… (ie: the file is composed of the above, followed by a new,empty line)
I’ve tried removing the newline and restarting Mycroft tho, and still the command is not recognized
I also tried “test this thing for me” as the command, but it is not recognized either.
I deleted and re-created the file with just a simple word in it (“lights”) and it IS working!

Given (the intention of) the code “lights on” should be written to make.request.intent

with the new content

test this thing for me\n
lights on

Sorry, just updated my last post:
I deleted and re-created the file with just a simple word in it (“lights”) and it IS working!

yeah, but this doesn’t resolve the core problem. This should automatcally be written as you change the config. (given the home config fetching algorithm got juiced)

Yep.
and I tought to play the smart guy and duplicate the skill (since as of now, I need at least two parameters: On and Off) and so have a skill for the “On” command and the other for the “Off” command but alas, this isn’t working either :slight_smile:

You could make something with “lights {status}” intent

and processing like
status = message.data.get(‘status’)
if status == “on”:
if status == “off”:

Thanks @SGee, but I’m really new at Mycroft :sweat_smile:
when you say:

make something with “lights {status}”

you mean writing in make.request.intent exactly: lights {status} ?
I tried doing this, and putting the logic in __init__.py but lights {status} isn’t recognized anymore as a command. (of course by speaking “Lights On”)
Again, pardon me but I’m a total noob at this

Update: I also tried with double curly braces ({{status}}) as explained here:


but still the command is not recognized

Lets stay with the intention of the code and iron out possible errors

i mean

fields:
       - name: trigger_phrase
         type: text
         label: Trigger phrase
         value: "lights {status}"

with

@intent_handler('make.request.intent')
    def handle_request(self, message):
        """Make the actual GET request."""
        status = message.data.get(‘status’)
        key = self.settings.get('param_key')
        if status == "on":
             value = self.settings.get('param_value')
        if status == "off":
             value = self.settings.get('param_value2')
        ...

I’ve found that Mycroft won’t react to the command specified in the settingsmeta.yaml, but just to the one in make.request.intent
maybe something else is broke… elsewhere?
Just to be sure, I rm -fr the skill and re cloned it with
mycroft-msm install https://github.com/krisgesling/make-get-request-skill
then edited the above files one at a time, same results :frowning:

maybe you are doing something wrong, you really should not edit settingsmeta.yaml, you should edit settings.yaml , the meta is for usage by the backend to display web settings

or maybe its the known selene bug, the backend is known to overwrite any changes you make locally to skill settings.

so installed the skill and added a trigger phrase
short time later (ckeck cli) make.request.intent looks like

turn lights {status}

you are running mycroft with lang=en-us?
since i had to copy the locales to de-de first to take effect (there are only en-us locales yet)

intent_file = /opt/mycroft/skills/make-get-request-skill.krisgesling/locale/de-de/make.request.intent` (in my case)

@SGee: yes, running with en-us
@JarbasAl: there’s no settings.yaml in this repo, I’ve tried updating settingsmeta from the device settings in the website, but it takes long for the settings to apply (if ever) so I was changing them direcly on disk