Hey @merphun,
https://github.com/wutu/pimatic-mqtt/issues/16
This week I’ll look into it. Sorry, I have little time.
-
New plugin pimatic-mqtt
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?
-
@Rene-Arts Hi.
Although I am now in the stage just before the laying of cables in Flat1
Yes, I watch it
I’m using now H801 in the kitchen with PIR.
I used MqttSwitch:{ "topic": "mh/ff/kitchen/dimmer/cmd", "onMessage": "pwm,15,1023,2000", "offMessage": "pwm,15,0,2000", "id": "cabinet-light", "name": "Cabinet light", "class": "MqttSwitch" }
You can also use dummy dimmer:
{ "id": "test-dimmer-with-transition", "name": "Test-dimmer-with-transition", "class": "DummyDimmer" }
{ "id": "test-dimmer-rules", "name": "Test-dimmer-rules", "rule": "when $test-dimmer-with-transition.dimlevel changes then publish mqtt message \"pwm,15,$test-dimmer-with-transition.dimlevel,500\" on topic \"mh/gf/lab/dimmer2/cmd\"", "active": true, "logging": true }
Value need to be converted for dimmer resolution. $test-dimmer-with-transition*1023/100 in this example.
ESP Easy newly used status topic for changes.
mh/gf/lab/dimmer2/status { "log": "GPIO 15 Set PWM to 23", "plugin": 1, "pin": 15, "mode": "PWM", "state": 23 }
I guess I’ll have to deploy something like msg template for all devices.
Pimatic = Smart Home
-
Thanks, that might give me a temporary solution. Also just got an idea to use the Rules in ESPEasy.
-
new version of pimatic-mqtt - 0.9.3
Fix sensor dev and change connection status detection@merphun Fixed
Pimatic = Smart Home