Two issues and 1 question with python snippets

  1. Parameters don’t seem to work, unless I’m not understanding them:

myIP = conf['secret']['HAIPAddress']

Errors the snippet. HAIPAddress is a valid secret. My config.ini file:

[secret]
HAPort=xxxx
HAIPAddress=xxx.xxx.xxx.xxx
HomeAssistantAPIPassword=xxxxxxxxx
  1. raw_value is not returned in intentMessage. The line myDeviceName fails

    if len(intentMessage.slots.device_name) > 0:
    myDeviceId = intentMessage.slots.device_name.first().value
    myDeviceName = intentMessage.slots.device_name.first().raw_value

Here’s the grab of the intent from MQTT. It should return ‘piano’:

{
  "sessionId":"ecad4158-6b60-4e1c-8042-98ae9e5d05c8",
  "customData":null,
  "siteId":"default",
  "input":"turn piano on off",
  "asrTokens":[[{
        "value":"turn",
        "confidence":0.8716052,
        "range_start":0,
        "range_end":4,
        "time":{
          "start":0,
          "end":0.031996407
        }
      },
      {
        "value":"piano",
        "confidence":0.8472208,
        "range_start":5,
        "range_end":10,
        "time":{
          "start":0.031996407,
          "end":1.4238567
        }
      },
      {
        "value":"on",
        "confidence":0.7749698,
        "range_start":11,
        "range_end":13,
        "time":{
          "start":1.4274645,
          "end":1.6021365
        }
      },
      {
        "value":"off",
        "confidence":0.7748795,
        "range_start":14,
        "range_end":17,
        "time":{
          "start":1.6021365,
          "end":2.5962558
        }
      }
    ]
  ],
  "intent":{
    "intentName":"wizbowes:turn_on",
    "probability":0.983512
  },
  "slots":[{
      "confidence":0.8472208,
      "rawValue":"piano",
      "value":{
        "kind":"Custom",
        "value":"light.fireplace_lights"
      },
      "range":{
        "start":5,
        "end":10
      },
      "entity":"device_name",
      "slotName":"device_name"
    },
    {
      "confidence":0.7749698,
      "rawValue":"on",
      "value":{
        "kind":"Custom",
        "value":"on"
      },
      "range":{
        "start":11,
        "end":13
      },
      "entity":"state",
      "slotName":"state"
    },
    {
      "confidence":0.7748795,
      "rawValue":"off",
      "value":{
        "kind":"Custom",
        "value":"off"
      },
      "range":{
        "start":14,
        "end":17
      },
      "entity":"state",
      "slotName":"state"
    }
  ]
  1. How do you import other packages into a snippet? I’m trying to import requests, but if fails with an unknown package. I’ve installed requests on python, but I’m guessing it doesn’t get brought into the virtual environment. I thought all installed packages were brought into a venv when it’s created - is this wrong. If not what’s the best way to bring this in?

Thanks in advance, and sorry for the deluge of posts at the moment. Try to get some ideas stuff working a published…

  1. try the secret name in lower case - if i remember correctly it only works that way (you found another one of the strange behaviors I guess ^^)

myIP = conf[‘secret’][‘haipaddress’]

  1. no idea for now…

  2. I went on to use github for multiple reasons - for example you can create your own requirements.txt and decide what to install into the venv

1 Like

Thanks Philipp. You’re doing a great job here.

I was hoping to avoid github. It’s only about 10 lines of code, and it seems much simpler if I could just use snippets. But if I must I must…

Hey Philipp - just a quick one as you’re using git. I’ve installed into git - but when I install the App I’m asked to chmod the actions file. Is this expected behaviour? I’ve not seen it on other skills I’ve installed but it might be being forced for GIT installs. It’s not clear although I found this is old release notes:

During sam install actions do not force chmod +x actions.py but asks the user to do it instead, raised for Github actions mostly

Or should I be putting that somewhere in my git files?

Apart from that (and the raw_value which I’ve raised a git issue for) all now seems to be working…

you can store it in the git index with the following command:

git update-index --chmod=+x $path-to-actions-file

For the second original question, the trick is to use something like this:

intentMessage.slots.slot_name[0].raw_value