@SaxnPaule
@wutu
Same error for me. this makes the plugin unuseable…
-
New plugin pimatic-mqtt
pimatic-google-calendar | pimatic-wmi | pimatic-snmp | pimatic-wakeonlan |
Like my work? Then consider a donation
Follow me: www.thorstenreichelt.de -
new version of pimatic-mqtt - 0.9.0
fix artifacts in actionsPimatic = Smart Home
-
Hi,
I use this MQTT client plugin to get location data from owntracks into variables which I can use to update pimatic location. Everything works as it should but one small issue:I have created a device (MQTTSensor) importing the topic of owntracks into two variables “lat” and "lon"
The variables are displayed correctly showing the numbers but if I try to update the location plugin with the lat and lon variables from this mqttsensor device the whole array from the owntracks topic is copied.So in short: Is there an option to just get the variable information? The device shows just the lat lon variables correctly but the information included in each lat and lon variable is not just the number but the whole topic:
So $Michael_mobile_phone.lat shows if I read it with a dummyvariabledevice:
e.g.: {"_type":“location”,“acc”:21,“batt”:91,“lat”:48.0181122,“lon”:16.2969471,“tid”:“mi”,“tst”:1474275140}
instead of just:
48.0181122Ine hint: I changed the $Michael_mobile_phone.lat to be a string (instead of number) as number cuts of the decimals just showing:
48.02
instead of
48.0181122In my view there is a behaviour in MQTTSensors wich maymbe should not be this way. Besides this is there a quick option to extract just the lat information from {"_type":“location”,“acc”:21,“batt”:91,“lat”:48.0181122,“lon”:16.2969471,“tid”:“mi”,“tst”:1474275140} and pasting it into a pimatic variable?
Br
Mike -
Hey @merphun,
https://github.com/wutu/pimatic-mqtt/issues/16
This week I’ll look into it. Sorry, I have little time.Pimatic = Smart Home
-
@merphun i have just created a new plugin pimatic-owntracks why dont you check it out?
-
Hi,
I checked it out but currently it shows if Ihe mobile is within a radius of a given location. I use the pimatic location plugin to display current location (Street and City) of all household members. Not just if someone is at home or at work.br
Mike -
Hey @developer
I’m preparing version who can connect with multiple brokers. I have this routine that converts config.class MqttPlugin extends env.plugins.Plugin init: (app, @framework, @config) => if not @config.brokers? active = @config.active delete @config.plugin delete @config.active @config["brokerId"] = "default" @config = {"plugin": "mqtt", "active": active, "brokers": [ @config ] } # @framework.saveConfig() << not working
Plugin starts correctly, but II can not figure out how to save it back to config.json.
Pimatic = Smart Home
-
@wutu It should save when pimatic stops. Can you pls check that? Meanwhile, I’ll have a look for method to sync the config explicitly.
"It always takes longer than you expect, even when you take into account Hofstadter's Law.", Hofstadter's Law
-
@mwittig Unfortunately, not save it all. Respectively saves only the changes
delete @config.plugin
delete @config.active
and@config["brokerId"] = "default"
.Pimatic = Smart Home
-
@wutu Hi. I have spent some time to investigate the matter. First of all you should use the prepareConfig() static member function to transform the config as needed (see code snippet below). prepareConfig() will be called by the framework before init is called. Note, you can also define prepareConfig() on your device classes which then will be called before the constructor is called.
Regarding framework.saveConfig() this simply does not work within the init() function as pimatic has not been fully initialized, yet. If you call it at a later stage (e.g., a deferred invocation) it will work as expected.
My advice to you is to simply forget about saveConfig() as I don’t see why you should need this. Normally, the config file will be written when pimatic terminates. If not, you simply start with the old config file and the prepareConfig() transformation will be applied again.
class MqttPlugin extends env.plugins.Plugin prepareConfig: (config) => if not config.brokers? active = config.active delete config.plugin delete config.active config["brokerId"] = "default" config = {"plugin": "mqtt", "active": active, "brokers": [ config ] } init: (app, @framework, @config) => ...
"It always takes longer than you expect, even when you take into account Hofstadter's Law.", Hofstadter's Law
-
-
@wutu This is as follow up on using the
prepareConfig
hook to transform the configuration of a device. Actually, it works a little bit different for device classes as the prepareConfig method needs to be provided as part of the configuration of the@framework.deviceManager.registerDeviceClass
invocation. Moreover, there is a specical notation for class methods which I found here: https://coffeescript-cookbook.github.io/chapters/classes_and_objects/class-methods-and-instance-methodsHere is an example of prepareConfig mtehod for a device
https://github.com/michbeck100/pimatic-dash-button/pull/7"It always takes longer than you expect, even when you take into account Hofstadter's Law.", Hofstadter's Law
-
Hi all.
@merphun Certainly, but a code MQTT sensor it is really no nice conglomerate. As soon as I finish multibrokers, I throw it out. I am considering using avalue_template
, just as it has HomeAssistant.@mwittig thx for your help and time.
On saveConfig () I was not concentrating. I used it only as a test of an error.
I probably just do not know how to correctly manipulate data.
If I use direct configuration settings it works:At the beginning I have this config (single Broker):
{ "plugin": "mqtt", "active": true, "host": "localhost", "port": 1883 }
And this code:
class MqttPlugin extends env.plugins.Plugin # transfer config - from single Broker to multiple Brokers prepareConfig: (config) => if not config.brokers? delete config.host delete config.port config.brokers = [ "brokerId": "default", "host": "localhost", "port": 1883 ] init: (app, @framework, @config) => ...
The plugin is started and the configuration is saved ok:
{ "plugin": "mqtt", "active": true, "brokers": [ { "brokerId": "default", "host": "localhost", "port": 1883 } ] }
The problem is that users can have a lot of config parameters. And I do not know how to get into
config.brokers
.Pimatic = Smart Home
-
@wutu said in New plugin pimatic-mqtt:
The problem is that users can have a lot of config parameters. And I do not know how to get into config.brokers
Ok. The legacy config parameters are for just for a single broker and now you have
config.brokers
which holds the config for multiple brokers. So,config.brokers
needs to be an array of objects, right?Please send me an example for a legacy setup and I’ll will draft something (including schema definition) .
"It always takes longer than you expect, even when you take into account Hofstadter's Law.", Hofstadter's Law
-
@mwittig said in New plugin pimatic-mqtt:
Ok. The legacy config parameters are for just for a single broker and now you have config.brokers which holds the config multiple brokers. So, brokwers needs to be an array of objects, right?
Yes
Please send me an example for a legacy setup and I’ll will draft something (including schema definition) .
Here is multiple brokers branche: https://github.com/wutu/pimatic-mqtt/tree/multibrokers
Pimatic = Smart Home
-
@wutu I have filed a PR to the multibrokers branch which includes an proposal for the implementation of the prepareConfig. I have tested this with a simple legacy config and the transformed configuration is properly shown in Plugin Editor. Please let me know what you think.
"It always takes longer than you expect, even when you take into account Hofstadter's Law.", Hofstadter's Law
-
@mwittig Thank you very much. After a small adjustment works!
But I had to add https://github.com/wutu/pimatic-mqtt/blob/multibrokers/mqtt.coffee#L38.
They dont know why, but this function requires"brokerId", "default"
set out explicitly in the config. And ignores the default settings.
Error:22:14:48.176 [pimatic] Error loading device "lab-dimmer-info": (@plugin.brokers[@config.brokerId]) 22:14:48.180 [pimatic] AssertionError: (@plugin.brokers[@config.brokerId])
Minimum config
{ "plugin": "mqtt", "active": true }
should be converted to
{ "plugin": "mqtt", "active": true, "brokers": [] }
and not
{ "plugin": "mqtt", "active": true, "brokers": [ { "brokerId": "default" } ] }
or (without https://github.com/wutu/pimatic-mqtt/blob/multibrokers/mqtt.coffee#L38)
{ "plugin": "mqtt", "active": true, "brokers": [ { } ] }
Pimatic = Smart Home
-
@wutu Great, it is working now! I only had tested with host and port set.
"It always takes longer than you expect, even when you take into account Hofstadter's Law.", Hofstadter's Law
-
thx @mwittig again
new version of pimatic-mqtt - 0.9.2
Support for multiple brokers
transition to mqtt.js 2.x.xPimatic = Smart Home
-
A question: is it possible to send two values via MQTT?
For example I am using ESPEasy on a H801 5 channel dimmer. Since a few months it is possible to not only send a new PWM value, but also a time (in ms) which the ESP should take to dim to the new value, e.g. 1000ms, which gives a nice fading effect of 1s. The time then should be the second argument.
Also see this topic on the ESPEasy forum: http://www.esp8266.nu/forum/viewtopic.php?f=6&t=1944#p9060There also seems to be a new template for setting outputs, maybe it is wise to accomodate for that as well?