Electricity pricing

Hi all - not sure what category this belongs in, any advice welcome.

I use an electricity company in New Zealand that charges customers based on the current spot pricing. So I have developed a python script which scrapes the current electricity price from the website and I would now like to use this in Home Assistant so that I can automatically control devices based on the current power price.

Just looking for some guidance on how to get this info into Home Assistant - should I develop a sensor or use the the Python Scripts component instead? Thanks.

Personally, I would use your existing scripts in command line sensor.

Thanks - that looks perfect. Except I canā€™t get the sensor to run the script. I can run the python script from the command line as the homeassistant user without issues, but it fails every time in the HA log:
2017-09-05 12:23:09 ERROR (Thread-3) [homeassistant.components.sensor.command_line] Command failed: python /home/homeassistant/.homeassistant/ha-flickprice.py

If run manually, the Python script just ā€˜printsā€™ the output to the terminal. How can I troubleshoot this to see why itā€™s failing?

Hereā€™s the sensor in my sensors.yaml file:

#Command Line sensor to get Flick price
- platform: command_line
  name: Flick Spot Price
  command: "python /home/homeassistant/.homeassistant/ha-flickprice.py"
  unit_of_measurement: "cents"
  scan_interval: 60

Replying to myself hereā€¦ ā€œVasileyā€ from the Discord site recommended I install hassctl and use the logging feature there to troubleshoot the script. This was perfect!

Hey there @stuartm - are you able to share this script?

Hi @jakebriggs, I donā€™t mind sharing it but Iā€™m in the process of reworking it now so that it works with Python3. Should be ready shortly but just to confirm this will only work with Flick Electricity - are you a customer of theirs?

cheers.

I certainly am a customer. No hurry, but it would be neat to be able to at least get the price :slight_smile: Maybe I could control my heatpump based on the priceā€¦

Hi again - finally got around to tidying up the script and have published to Github here: https://github.com/stuartmaxwell/spotprice

1 Like

Just wanted to say thanks for this. I have just got it working with my Hassio install and with the way the spot prices are at the moment it gonna be really handy making sure certain things arnā€™t on when the prices goes up stupid high.

Cheers

Hi guys,

How do I get this going with HASS.io?

Where would I clone the python scripts to? Somewhere in the config directory? How then do I call it so that it generates the credentials file, as Iā€™m guessing setting it up as a sensor wonā€™t exactly yield a credentials file? Also, what about pipenv and those dependencies? They will also need to be installed somehow.

Let me know, because Iā€™m quite exicted about this :slight_smile: