Create a "virtual" device - setting values via http

Hello everyone.

I am new at the Home Assistent Community. I have tried several platforms before. From fibaro hcl over homee. At the moment I use honey.

I have a test configuration running at the moment but before buying als the hardware to connect zwave, enocean an zigbee I want to check some stuff.

I have a smart meter installed and a python script reading the values from it. I want to send the values of the power consumption to home assistant and use them there. In best case some kind of custom/virtual device.
Can I implement something with hass and how?

Thank you very much.
Sebastian

Ps: if this is the wrong place in the forum let me know.

Tldr;
How to set a value of a device with http calls?

You can do this via the API, or, what i do, publish the values from the python script to mqtt and use mqtt sensors in HA.

Ok great thanks. And how do I create a “dummy” device to set the value via API? I don’t want to use mqtt if not necessary

It gets created by the api post if it doesn’t exists.
A simple example:

import requests

url = 'http://localhost:8123/api/states/sensor.my_test_sensor'

headers = {
    'Authorization': 'Bearer abcde',
    'content-type': 'application/json'
}

data = '{"state": "test_value"}'

r = requests.post(url, data=data, headers=headers)
print(r)

creates sensor.my_test_sensor and sets the state.
Auswahl_414

1 Like

Just curious, why do you not want to use MQTT? Sooner or later you’ll probably end up using it anyway. E.g. the new zwave integration works through openzwave, which requires MQTT.

Just. Because I don’t want to maintain the infrastructure. If I have to to use zwave it’s fine. But to set one value for one device looked to be overkill.

And in addition my script is already finished and it uses only http calls and not mqtt.

FWIW the only infrastructure you have to maintaim is an MQTT broker and for the last 3 years I didn’t need to do anything with the MQTT broker apart from updating every few months.

Ok, it would be pretty easy to adapt this to MQTT.

Sure thank you. I only wanted to keep it simple for the start. But I understand your point.

At this point I am just think about moving all my stuff over to hass and evaluating the cases I have in homey at the moment.

1 Like