Skip to content

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.

License

Notifications You must be signed in to change notification settings

DSorlov/http_agent

Repository files navigation

maintained hacs_badge ha_version version stability CI hassfest HACS maintainer License

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 both JSON, XML and even HTML/CSS-Selectors. 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 Configuration β†’ Integrations
  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 or CSS selectors.
  • 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

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.pressure

XML 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']/icon

HTML Scraping Example

URL: https://example.com/status
Method: GET
Sensors:
  - Name: Status
    Method: CSS
    State: .status-value
    Color: .status-indicator
    Icon: .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

License

Contributing

Security policy

Stars

Watchers

Forks

Packages

No packages published

Contributors 2

  •  
  •  

Languages