DSorlov/http_agent
This is a simple HTTP Agent that calls a URL at a given intervall and stores the result in the sensor. Also Actions and Services to use in your own advanced projects.
HTTP Agent for Home Assistant
HTTP Agent is a powerful Home Assistant custom integration that creates individual HTTP sensor instances with advanced data extraction capabilities supporting JSON, XML, HTML/CSS-Selectors and Regular Expressions. Unlike traditional hub-based integrations, each HTTP endpoint becomes its own integration instance and then you can define multiple sensors for that request.
Installation
Via HACS (Recommended)
- Open HACS in Home Assistant
- Go to "Integrations"
- Click the "+" button
- Search for "HTTP Agent"
- Install the integration
- Restart Home Assistant
Manual Installation
- Copy the
custom_components/http_agentfolder to yourcustom_componentsdirectory - Restart Home Assistant
Configuration
Adding the Integration
- Go to Configuration โ Integrations
- Click + Add Integration
- Search for "HTTP Agent"
- Follow the setup wizard to configure your integration
Configuration
Step 1: URL Configuration
- URL: The HTTP endpoint to poll (supports templates)
- Method: HTTP method (GET, POST, PUT, DELETE, PATCH)
- Timeout: Request timeout in seconds (1-300)
- Update Interval: How often to poll in seconds (5-86400)
Step 2: Headers (Optional)
Add any HTTP headers needed for authentication or content negotiation.
Step 3: Payload (For POST/PUT/DELETE/PATCH)
Configure request body with content type selection. The field supports templates.
Step 4: Sensors
Define sensors to extract data from the response:
- Name: Sensor name
- Extraction Method: JSON, XML, CSS selectors or Regular Expression.
- State: Main sensor value selector/template
- Icon: Icon selector/template (auto-prefixed with
mdi:) - Color: Color selector/template
Extraction Methods
JSON
Use dot notation to access JSON properties:
temperature # Simple property
sensors.0.value # Array index
metadata.device.id # Nested objects
XML
Use XPath expressions:
./temperature # Direct child
.//sensor[@name='temp1']/@value # Attribute search
./metadata/battery # Nested elements
CSS Selectors
Use CSS selectors for HTML content:
.temperature # Class selector
#sensor-value # ID selector
div[data-sensor="temp"] # Attribute selector
Regular Expressions
Use regular expressions for text content, use PCRE-format delimiters /pattern/flags:
/Some Text: ([0-9]+)/ # single group
/some text: ([0-9]+)/i # case insensitive
/Some Text: ([0-9]+) other text ([a-z]+) # multiple groups, result will be merged "group 1|group 2"
Template Support
All configuration fields support Home Assistant templates:
URL Templates
http://api.example.com/sensors/{{ states('input_text.device_id') }}
Header Templates
Key: Authorization
Value: Bearer {{ states('input_text.api_token') }}
Payload Templates
{
"device": "{{ states('input_text.device_name') }}",
"timestamp": "{{ now().isoformat() }}"
}Examples
JSON API Example
URL: https://api.weather.com/v1/current
Method: GET
Headers:
- API-Key: your-api-key
Sensors:
- Name: Temperature
Method: JSON
State: current.temperature
Icon: current.condition_icon
Attributes:
- Humidity: current.humidity
- Pressure: current.pressureXML API Example
URL: https://api.example.com/data.xml
Method: GET
Sensors:
- Name: Sensor Value
Method: XML
State: ./sensors/sensor[@id='temp1']/value
Icon: ./sensors/sensor[@id='temp1']/iconHTML Scraping Example
URL: https://example.com/status
Method: GET
Sensors:
- Name: Status
Method: CSS
State: .status-value
Color: .status-indicator
Icon: .status-iconTroubleshooting
Enable Debug Logging
Add to configuration.yaml:
logger:
logs:
custom_components.http_agent: debugContributing
Contributions are welcome! Please feel free to submit a Pull Request.
License
This project is licensed under the MIT License - see the LICENSE file for details.
Support
- ๐ Report a Bug
- ๐ก Request a Feature
- ๐ Documentation
Changelog
See CHANGELOG.md for version history.