fhem http support

Moderators: grovkillen, Stuntteam, TD-er

Post Reply
Message
Author
kroonen
Normal user
Posts: 26
Joined: 05 Oct 2015, 22:00

fhem http support

#1 Post by kroonen » 05 Oct 2015, 22:24

Hi,

I'm using them as domotica software. It should be nice to also have that supported.

I have an example of lua how I post it to fhem. It looks like domoticz post. It's based on a si7021 i2c sensor


tmr.alarm(0, 90000, 1, function()

SDA_PIN = 3 -- sda pin, GPIO0
SCL_PIN = 4 -- scl pin, GPIO2

si7021 = require("si7021")
si7021.init(SDA_PIN, SCL_PIN)
si7021.read(OSS)
h = si7021.getHumidity()/100
t = si7021.getTemperature()/100

function round(n)
return n % 1 >= 0.5 and math.ceil(n) or math.floor(n)
end

hum = tonumber(string.format("%." .. (1) .. "f", h))
hum = round(hum)
temp = tonumber(string.format("%." .. (1) .. "f", t))

-- release module
si7021 = nil
package.loaded["si7021"]=nil


conn=net.createConnection(net.TCP, 0)
conn:on("receive", function(conn, payload) print(payload) end )
conn:connect(8083,"192.168.180.5")
conn:send('GET /fhem?cmd=setreading%20Slaapkamertemp%20state%20T:%20' ..temp.. '%20H:%20'..hum..'\r\n HTTP/1.1\r\nHost: www.local.lan\r\n".."Connection: keep-alive\r\nAccept: */*\r\n\r\n"')
end)

kroonen
Normal user
Posts: 26
Joined: 05 Oct 2015, 22:00

Re: fhem http support

#2 Post by kroonen » 08 Nov 2015, 20:50

Hi,

I now tried it with mqtt to fhem. That works a little. I get this in fhem (when using the domotiqz mqtt)

start {"idx":2,"nvalue":0,"svalue":"19.96;74.00;0"}
2015-11-08 20:46:52 transmission-state incoming publish received

I get this as value: {"idx":2,"nvalue":0,"svalue":"19.96;74.00;0"}

Is there a way to only get: 19.96 74.00 or T 19.96 H 74.00

Than it should be simple to get it working

Regards Richard

Niklas
New user
Posts: 4
Joined: 26 Oct 2015, 22:57

Re: fhem http support

#3 Post by Niklas » 12 Nov 2015, 22:30

Hi kroonen,

coul you tell me please how you configured the FHEM MQTT_Device?
I can't read anything in FHEM up to now.

Thanks!
BR
Niklas

kroonen
Normal user
Posts: 26
Joined: 05 Oct 2015, 22:00

Re: fhem http support

#4 Post by kroonen » 14 Nov 2015, 13:08

Niklas,

Make tins working in them

define mqtt MQTT 127.0.0.1:1883
define mqtt_testtemp MQTT_DEVICE testtemp
attr mqtt_testtemp subscribeReading_start fhem/temp

And try with local mosquito tool on them server

mosquitto_pub -t fhem/temp -m test

Than choose in espeasy, domoticz mqtt, and choose port 1883, and ip adds where your fhem/mqtt stands

than on tools advanced. mutt publish template to fhem/temp

than you get those readings

regards Richard

Niklas
New user
Posts: 4
Joined: 26 Oct 2015, 22:57

Re: fhem http support

#5 Post by Niklas » 14 Nov 2015, 18:31

Hi Richard,

I tried exactly what you wrote.
With the local try and with an Android MQTT App it is working, but my ESPEasy always tells me "Failed to connected to broker".
Tere still seems to be something wrong.

BR
Niklas

kroonen
Normal user
Posts: 26
Joined: 05 Oct 2015, 22:00

Re: fhem http support

#6 Post by kroonen » 15 Nov 2015, 11:27

Niklas,

You change controller port to 1883?

and protocol to domotcz mqtt
and on advanced config the publish template to the right topic for example fhem/temp?

and did a submit and checked the values

regards richard

Martinus

Re: fhem http support

#7 Post by Martinus » 15 Nov 2015, 13:33

kroonen wrote:Is there a way to only get: 19.96 74.00 or T 19.96 H 74.00
Regards Richard
Maybe you can try the Pidome configuration where single values are published instead of json format.
It should publish each individual value.

kroonen
Normal user
Posts: 26
Joined: 05 Oct 2015, 22:00

Re: fhem http support

#8 Post by kroonen » 15 Nov 2015, 14:45

You are right, that al the values are separate pushed. I asked in fhem forum how to create sensors for this

http://forum.fhem.de/index.php/topic,43669.0.html

Martinus

Re: fhem http support

#9 Post by Martinus » 15 Nov 2015, 15:05

kroonen wrote:You are right, that al the values are separate pushed. I asked in fhem forum how to create sensors for this

http://forum.fhem.de/index.php/topic,43669.0.html
What template are you using in MQTT publish?

kroonen
Normal user
Posts: 26
Joined: 05 Oct 2015, 22:00

Re: fhem http support

#10 Post by kroonen » 15 Nov 2015, 15:42

I change the template to fhem/temp
mqtt.tiff
mqtt.tiff (17.98 KiB) Viewed 10763 times
because else I get nog values?

Or should I name the mqtt broker different? Now i call it in fhem

subscribeReading_start fhem/temp

Now I get the values like this

2015-11-15_15:35:02 mqtt_testtemp transmission-state: incoming publish received
2015-11-15_15:35:02 mqtt_testtemp start: 19.69
2015-11-15_15:35:02 mqtt_testtemp transmission-state: incoming publish received
2015-11-15_15:35:02 mqtt_testtemp start: 1012.95
2015-11-15_15:35:03 mqtt_testtemp transmission-state: incoming publish received
2015-11-15_15:35:03 mqtt_testtemp start: 19.57
2015-11-15_15:35:03 mqtt_testtemp transmission-state: incoming publish received
2015-11-15_15:35:03 mqtt_testtemp start: 66.00


It should be nice to have it like this

2015-11-15_15:35:02 mqtt_testtemp start: 19.69 1012.95 19.57 66.00

Than I can strip it in fhem

Martinus

Re: fhem http support

#11 Post by Martinus » 15 Nov 2015, 17:38

I think you need something like these samples:

/%sysname%/%tskname%/%valname%
/hooks/devices/%id%/SensorData/%valname%

or else all values would be published on the same channel and you will not be able to tell which is which.
Domoticz uses json over mqtt so json tells all information about the device. If we publish single values, they should be on different channels.

So it guess it could be something like:

/fhem/esp1/livingroom/temperature
/fhem/esp1/livingroom/humidity
/fhem/esp1/kitchen/temperature
/fhem/esp2/shed/temperature
/fhem/esp1/shed/humidity

where fhem controller should listen to /fhem/#

If you check with openhab of pidome, each device listens to a specific published channel.

kroonen
Normal user
Posts: 26
Joined: 05 Oct 2015, 22:00

Re: fhem http support

#12 Post by kroonen » 15 Nov 2015, 18:10

I can use that so what value is what?

Using pidome mqtt

/fhem/%id%/%valname% is that is correct that /fhem/idx/Temperature for this?


So fhem/1/Temperature for test?


So is %id% the idx/variable?

regards Richard

Niklas
New user
Posts: 4
Joined: 26 Oct 2015, 22:57

Re: fhem http support

#13 Post by Niklas » 15 Nov 2015, 18:57

Hi Richard,

my main problem was that I could not connect to the broker due to a wrong /etc(network/interfaces configuration on my pi. Now I solved this problem and could read Temperature and Humidity separately:

ESPEasy:
set PiDome MQTT
leave Tools/System/Advanced as it is

FHEM:
define mqtt MQTT IP:Port
define mqtt_DHT22 MQTT_DEVICE
attr mqtt_DHT22 IODev mqtt
attr mqtt_DHT22 autoSubscribeReadings /hooks/devices/15/SensorData/+
attr mqtt_DHT22 stateFormat Temperatur: Temperature°C Luftfeuchtigkeit: Humidity%rH
attr mqtt_DHT22 subscribeReading_Humidity /hooks/devices/15/SensorData/Humidity
attr mqtt_DHT22 subscribeReading_Temperature /hooks/devices/15/SensorData/Temperature

I hope this helps.

kroonen
Normal user
Posts: 26
Joined: 05 Oct 2015, 22:00

Re: fhem http support

#14 Post by kroonen » 15 Nov 2015, 19:22

Niklas,

That works . Thnx.

regards Richard

kroonen
Normal user
Posts: 26
Joined: 05 Oct 2015, 22:00

Re: fhem http support

#15 Post by kroonen » 16 Nov 2015, 20:21

Still one question

I Want for example nog 21.07 but rounded with 1 decimal, 21.1 and for humidity you only 70 and not 70.00

Any idea if this could be in esp easy with formula, or is it possible in fhem?

regards Richard

Post Reply

Who is online

Users browsing this forum: Bing [Bot] and 2 guests