Skip to content

Repository files navigation

maintainedhacs_badgeha_versionversionstabilityCIhassfestHACSmaintainerLicense

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)

  1. Open HACS in Home Assistant
  2. Go to "Integrations"
  3. Click the "+" button
  4. Search for "HTTP Agent"
  5. Install the integration
  6. Restart Home Assistant

Manual Installation

  1. Copy the custom_components/http_agent folder to your custom_components directory
  2. Restart Home Assistant

Configuration

Adding the Integration

  1. Go to ConfigurationIntegrations
  2. Click + Add Integration
  3. Search for "HTTP Agent"
  4. 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/currentMethod: GETHeaders:
- API-Key: your-api-keySensors:
- Name: TemperatureMethod: JSONState: current.temperatureIcon: current.condition_iconAttributes:
- Humidity: current.humidity
- Pressure: current.pressure

XML API Example

URL: https://api.example.com/data.xmlMethod: GETSensors:
- Name: Sensor ValueMethod: XMLState: ./sensors/sensor[@id='temp1']/valueIcon: ./sensors/sensor[@id='temp1']/icon

HTML Scraping Example

URL: https://example.com/statusMethod: GETSensors:
- Name: StatusMethod: CSSState: .status-valueColor: .status-indicatorIcon: .status-icon

Troubleshooting

Enable Debug Logging

Add to configuration.yaml:

logger:
logs:
custom_components.http_agent: debug

Contributing

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

Changelog

See CHANGELOG.md for version history.

About

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.

Topics

Resources

Contributing

Security policy

Stars

9 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages