I'm attempting to make the script for Pyiqvia work in openhab

I’m attempting to make the script for Pyiqvia work in openhab. I’ve got some knowledge in HTML,PHP and css, however this is python. I’m hoping someone can help point me in the correct direction on how to proceed.

I’ve copied the git and gotten it installed, updated it with my zip code and when I run the sample script it spits out the data… Now I just need to capture that and pull into habpanel…

the test_api.py outputs the following when run:

Allgergen, Disease, Asthma

Client instantiated for ZIP "68xxx"

Allergen Data:
{'Type': 'pollen', 'ForecastDate': '2020-03-15T00:00:00-04:00', 'Location': {'ZI                                                                                             P': '68xxx', 'City': 'OMAHA', 'State': 'NE', 'periods': [{'Triggers': [{'LGID':                                                                                              4, 'Name': 'Maple', 'Genus': 'Acer', 'PlantType': 'Tree'}, {'LGID': 272, 'Name':                                                                                              'Juniper', 'Genus': 'Juniperus', 'PlantType': 'Tree'}, {'LGID': 106, 'Name': 'E                                                                                             lm', 'Genus': 'Ulmus', 'PlantType': 'Tree'}], 'Period': '0001-01-01T00:00:00', '                                                                                             Type': 'Yesterday', 'Index': 0.8}, {'Triggers': [{'LGID': 4, 'Name': 'Maple', 'G                                                                                             enus': 'Acer', 'PlantType': 'Tree'}, {'LGID': 272, 'Name': 'Juniper', 'Genus': '                                                                                             Juniperus', 'PlantType': 'Tree'}, {'LGID': 106, 'Name': 'Elm', 'Genus': 'Ulmus',                                                                                              'PlantType': 'Tree'}], 'Period': '0001-01-01T00:00:00', 'Type': 'Today', 'Index                                                                                             ': 6.6}, {'Triggers': [{'LGID': 4, 'Name': 'Maple', 'Genus': 'Acer', 'PlantType'                                                                                             : 'Tree'}, {'LGID': 272, 'Name': 'Juniper', 'Genus': 'Juniperus', 'PlantType': '                                                                                             Tree'}, {'LGID': 106, 'Name': 'Elm', 'Genus': 'Ulmus', 'PlantType': 'Tree'}], 'P                                                                                             eriod': '0001-01-01T00:00:00', 'Type': 'Tomorrow', 'Index': 6.5}], 'DisplayLocat                                                                                             ion': 'Omaha, NE'}}
{'Type': 'pollen', 'ForecastDate': '2020-03-15T00:00:00-04:00', 'Location': {'ZI                                                                                             P': '68xxx', 'City': 'OMAHA', 'State': 'NE', 'periods': [{'Period': '2020-03-15T                                                                                             07:30:21.073', 'Index': 6.6}, {'Period': '2020-03-16T07:30:21.073', 'Index': 6.5                                                                                             }, {'Period': '2020-03-17T07:30:21.073', 'Index': 6.4}, {'Period': '2020-03-18T0                                                                                             7:30:21.073', 'Index': 5.7}, {'Period': '2020-03-19T07:30:21.073', 'Index': 5.9}                                                                                             ], 'DisplayLocation': 'Omaha, NE'}}

If I’m successfull in getting this to pull this into Habpanel, or collect it into something like /static/html/pyiqvia.html then I hope to turn this into a widget that I can share with others. Right now though I’m just trying to get this to work.

Thanks for reading and if you have any advice I’m very grateful for it.

Have you looked at using Jython automation? It is Python 2 compatible. @rlkoshak and @5iver are a couple of experts here.

While I absolutely support people getting into scripted automation and using Jython, Nate’s script is Python 3. I’m sure it could be converted though!

I suggest adding some API calls into the script to add the data directly to Items within OH.

2 Likes

Not yet, but that sounds like something I should be looking into if it will work. Thanks for the suggestion!

1 Like

Ok, I’ll see what I can in the API aspect. Thanks!

You can run your script in HABApp without changes since HABApp is python 3.

2 Likes

I’m still going to finish this python course I’m watching, but I think I’ll use Habapp in the meantime! Thanks!

1 Like

I’m going to write up a tutorial if I can get this doing what I want, since I don’t see any way to currently pull in Pollen counts easily.

1 Like

That would be really nice. If you need help with HABApp or the integration just ping me :slight_smile:

Edit:
I guess it’s should be something like this:

import datetime
from pyiqvia import Client

from HABApp import Rule
from HABApp.openhab.items import NumberItem


class PyiqviaRule(Rule):

    def __init__(self):
        super().__init__()
        self.run_every(
            time=datetime.timedelta(minutes=5),
            interval=datetime.timedelta(hours=9),
            callback=self.check_pollen
        )
        
        self.my_number = NumberItem.get_item('MyOpenhabItem')
        

    async def check_pollen(self):
        with self.async_http.get_client_session() as websession:
            client = Client(80012, websession)
                # ZIP codes starting with 0 need to be provided as strings:
            client = Client('00544', websession)
    
            # Get current allergen information:
            await client.allergens.current()
    
            # Get more information on the current allergen outlook:
            await client.allergens.outlook()

            ...
            
            # extract your numbers and post them like this
            self.my_number.oh_post_update(99)


PyiqviaRule()
1 Like

Thanks!

do I need to move the Pyiqvia script into Scripts path in Openhab?

I’m getting

11:42:48.460 [WARN ] [del.core.internal.ModelRepositoryImpl] - Configuration model ‘habapptest.rules’ has errors, therefore ignoring it: [1,8]: no viable alternative at input ‘from’
[2,21]: no viable alternative at input ‘from’
[4,20]: no viable alternative at input ‘from’
[5,34]: no viable alternative at input ‘class’

EDIT: I didn’t see the rules folder inside the HABApp structure.