Amazon Price - Custom Sensor to track Amazon Prices

Hello @Cain

I just uploaded the new version. Now showing the seller.

Kind regards Mike

Hello @anon35356645,

new version is up now you have {{states.sensor.efergy_it.attributes[‘Blank Original price’]}} to get the price without currency

Kind Regards
Mike Auer

this sounds great can’t wait :wink:

I cannot get the custom_component working. It throws:

2018-05-12 20:58:21 ERROR (MainThread) [homeassistant.components.sensor] amazon_price: Error on device update!
Traceback (most recent call last):
File “/home/homeassistant/.homeassistant/custom_components/sensor/amazon_price.py”, line 124, in update
SALE_CURRENCY,SALE_BPRC = (‘’.join(‘’.join(RAW_SALE_PRICE).split()).strip()).split(’ ') if RAW_SALE_PRICE else None
ValueError: not enough values to unpack (expected 2, got 1)

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File “/opt/homeassistant/lib/python3.6/site-packages/homeassistant/helpers/entity_platform.py”, line 244, in _async_add_entity
await entity.async_device_update(warning=False)
File “/opt/homeassistant/lib/python3.6/site-packages/homeassistant/helpers/entity.py”, line 327, in async_device_update
yield from self.hass.async_add_job(self.update)
File “/usr/lib/python3.6/concurrent/futures/thread.py”, line 56, in run
result = self.fn(*self.args, **self.kwargs)
File “/opt/homeassistant/lib/python3.6/site-packages/homeassistant/util/init.py”, line 319, in wrapper
result = method(*args, **kwargs)
File “/home/homeassistant/.homeassistant/custom_components/sensor/amazon_price.py”, line 155, in update
raise ValueError(e)
ValueError: not enough values to unpack (expected 2, got 1)

My conf is:

 - platform: amazon_price
   domain_ending: de
   items:
     - asin: B001LQSFKY
       name: MFSL Original Master Sleeves
     - asin: B073WSCQWV
       name: Expower Smart LED WiFi Lampe
     - asin: B00M0GLHPY
       name: Monkey Business Schwein Ei-Separator

Hmm, getting errors trying to use in this in hass.io:

Unable to install package lxml==4.1.1: Command "/usr/bin/python3 -u -c "import setuptools, tokenize;__file__='/tmp/pip-build-bbwz4x5t/lxml/setup.py';f=getattr(tokenize, 'open', open)(__file__);code=f.read().replace('\r\n', '\n');f.close();exec(compile(code, __file__, 'exec'))" install --record /tmp/pip-fgp9g0ej-record/install-record.txt --single-version-externally-managed --prefix --compile --user --prefix=" failed with error code 1 in /tmp/pip-build-bbwz4x5t/lxml/

I get this error now

2018-06-11 12:01:30 ERROR (SyncWorker_18) [homeassistant.util.package] Unable to install package lxml==4.1.1: Command “/usr/bin/python3 -u -c “import setuptools, tokenize;file=’/tmp/pip-build-dwtlybtf/lxml/setup.py’;f=getattr(tokenize, ‘open’, open)(file);code=f.read().replace(’\r\n’, ‘\n’);f.close();exec(compile(code, file, ‘exec’))” install --record /tmp/pip-u4hkzi93-record/install-record.txt --single-version-externally-managed --prefix --compile --user --prefix=” failed with error code 1 in /tmp/pip-build-dwtlybtf/lxml/
2018-06-11 12:01:30 ERROR (MainThread) [homeassistant.requirements] Not initializing sensor.amazon_price because could not install requirement lxml==4.1.1
2018-06-11 12:01:30 ERROR (MainThread) [homeassistant.setup] Unable to prepare setup for platform sensor.amazon_price: Could not install all requirements.

Sorry to bump this thread. But it is no longer working for quite sometime. Appreciate if someone can make it works again. Thanks.

It looks like the repo hasn’t been updated for over a year, which is a shame as this is quite handy sensor.

Sorry for bumping this

HI All,

I saw this sensor yesterday and as i was interested i started to rewrite this sensor.
As the current sensor wasnt updated for 2 years and not working on newer versions of HA

Its still in the begin fase so it will take a while before i have it up and running.
I currently have it working with again on 0.107.0b5 but only with basic information as name and price of the product.

As soon as i have a better working version i will post it on my github page.

Kind Regards,
Dion

Update, there is a initial release available, will only get name and price.

need to work on the rest, but because of work this will take a while.

3 Likes

Great work, thank you!

I was trying to track Apple Airpods pro on amazon.fr but for some reason it doesn’t work, the sensor status returns “unknown”. Any idea why? thank you.

Actually it doesn’t work with the French version of amazon web site :frowning:

I am far from being an expert in coding, but after a bit of investigation the following two lines return no values:

RAW_NAME = doc.xpath('//span[contains([@id](https://github.com/id),"productTitle") or contains([@id](https://github.com/id),"Title")]/text()')
RAW_SALE_PRICE = doc.xpath('//span[contains([@id](https://github.com/id),"priceBlockStrikePriceString") or contains([@id](https://github.com/id),"priceblock_ourprice")]/text()')

Which is very strange since the span structure and naming of the French web site is the same as the NL, DE, ENG web sites.

I don’t know how to fix that :frowning:

Hi,

not sure why there is a github url in your id field:

RAW_NAME = doc.xpath('//span[contains([@id](https://github.com/id),"productTitle") or contains([@id](https://github.com/id),"Title")]/text()')
RAW_SALE_PRICE = doc.xpath('//span[contains([@id](https://github.com/id),"priceBlockStrikePriceString") or contains([@id](https://github.com/id),"priceblock_ourprice")]/text()

it should be like this

            RAW_NAME = doc.xpath('//span[contains(@id,"productTitle") or contains(@id,"Title")]/text()')
            RAW_SALE_PRICE = doc.xpath('//span[contains(@id,"priceBlockStrikePriceString") or contains(@id,"priceblock_ourprice")]/text()')

Hi, thanks for your answer. I don’t know neither where this github http address comes from, that is not what I copied/pasted.

I found the issue and fixed it, the Amazon French web site is blocking robots with a captcha.

Hi! Would you please share your fix? Trying with Amazon Italy but the sensor always results “unknown”.
Thanks!

Hi. I used browser spoofing and changed the http-agent in the python script.

Lovely!
That’s too much for me.
I’ll wait for a proper patch by the author, if ever :grinning:

Hi,

I keep getting the following error:

Platform error sensor.amazon_pw - Integration ‘amazon_pw’ not found.

Do i add the sensor.py directly into my custom_components folder or do i need to do something else. Please help! Bit of a noob with home assistant still.

It should be in /custom_componets/amazon_pw/ as below.
image

@Mkipz However, I just tested, and it’s throwing the following error.

amazon_pw: Error on device update!
Traceback (most recent call last):
  File "/srv/homeassistant/lib/python3.7/site-packages/homeassistant/helpers/entity_platform.py", line 335, in _async_add_entity
    await entity.async_device_update(warning=False)
  File "/srv/homeassistant/lib/python3.7/site-packages/homeassistant/helpers/entity.py", line 457, in async_device_update
    self.update  # type: ignore
  File "/usr/local/lib/python3.7/concurrent/futures/thread.py", line 57, in run
    result = self.fn(*self.args, **self.kwargs)
  File "/srv/homeassistant/lib/python3.7/site-packages/homeassistant/util/__init__.py", line 239, in wrapper
    result = method(*args, **kwargs)
  File "/home/homeassistant/.homeassistant/custom_components/amazon_pw/sensor.py", line 93, in update
    from lxml import html
ModuleNotFoundError: No module named 'lxml'

@DKO75 Do you mind sharing the steps to accomplish this?

Hi,

I understand this is your very old post, however, i was hoping if you could re-share this integration please?

Thanks