| .. | ||
| fetch_costco_prices.sh | ||
| README.md | ||
Costco Fuel Price script for a Home Assistant sensor
Home Assistant configuration.yaml
To execute your shell script every 6 hours and expose the extracted fuel prices as sensors in Home Assistant, you'll follow these steps:
- Create the Shell Command in Home Assistant Ensure that the shell command integration is enabled in your Home Assistant configuration by adding this to configuration.yaml:
shell_command:
fetch_costco_fuel_prices: /config/scripts/fetch_costco_prices.sh
Save your script as fetch_costco_prices.sh in the /config/scripts directory or modify the path accordingly.
- Add a Command-Line Sensor for Each Variable Use command-line sensors to expose the extracted values. Here's how you can do it in your configuration.yaml file:
sensor:
- platform: command_line
name: Costco Premium Diesel
command: "bash /config/scripts/fetch_costco_prices.sh | jq -r '.premium_diesel'"
scan_interval: 21600 # Every 6 hours
- platform: command_line
name: Costco Premium Unleaded
command: "bash /config/scripts/fetch_costco_prices.sh | jq -r '.premium_unleaded'"
scan_interval: 21600 # Every 6 hours
- platform: command_line
name: Costco Unleaded Petrol
command: "bash /config/scripts/fetch_costco_prices.sh | jq -r '.unleaded'"
scan_interval: 21600 # Every 6 hours
Here, scan_interval: 21600 sets the sensors to update every 6 hours (21600 seconds). The command extracts the respective JSON values from the script output using jq.
- Make Sure Dependencies Are Installed For this setup:
curl should already be installed on most systems. Ensure jq is installed (used to parse JSON output). On Debian-based systems, you can install it using:
sudo apt-get install jq
- Testing the Configuration Before restarting Home Assistant, validate your configuration:
ha core check
If no errors are shown, restart Home Assistant to apply the new configuration:
ha core restart
This configuration will execute the script every 6 hours to retrieve the latest fuel prices and expose them as sensors in Home Assistant. You can then use these sensors in automations, dashboards, or other components as needed.