FHEM Forum

FHEM => English Corner => Thema gestartet von: andyclimb am 05 Juni 2015, 16:07:42

Titel: Creating a new device / grouping
Beitrag von: andyclimb am 05 Juni 2015, 16:07:42
Hello all,

I've build some lamps using the new ESP8266, that can be controlled using MQTT or HTTP, maybe even web sockets soon... although i have to learn about it. They got lots of settings, including mode (nearly 20), colour, pattern, speed, animation speed..  so I've created a dummy device for each one, and then an MQTT_BRIDGE device for each one of these, and it works but i need to create a lot of devices to do the controlling...  anyway... the point is that all these dummy devices to do the controlling take up a LOT of space in the room... which also has temp, humidity, etc etc..

What I would like is to be able to create a super device... and have these devices all nested inside as sub devices... say with the super device just presenting one thing.  Kind of how device implementations work at the moment..

Has online thought of this problem before / requested something like it / got any working solutions... 


Thought i'd share a picture of my lamp...
Titel: Antw:Creating a new device / grouping
Beitrag von: andyclimb am 05 Juni 2015, 16:09:41
Here it is...
(https://dl.dropboxusercontent.com/u/12627633/IMG_0049.JPG) and it animates, has UDP streaming, and hyperion/ambilight via serial (adalight) capabilities... all from an ESP8266
Titel: Antw:Creating a new device / grouping
Beitrag von: Fritz!Maxi am 05 Juni 2015, 21:23:49
Wow, looks awesome!
Titel: Antw:Creating a new device / grouping
Beitrag von: rudolfkoenig am 06 Juni 2015, 07:43:59
I see the following alternatives:
- instead of a bunch of dummy devices use one dummy device with a bunch of readings.
- use readingsGroup
- build you own module :)
Titel: Antw:Creating a new device / grouping
Beitrag von: andyclimb am 08 Juni 2015, 18:19:57
Thank you for the advice. 

Is there a way of having different input methods for readings within one dummy device...

i'd like a drop down box for effects. A slider for animation timer.   

I think building my own module is the way forward.  but i have no experience with this or with perl... so this might be a long road.

I'm not entirely sure what is possible using readingsGroup so i need to look into it. 

Titel: Antw:Creating a new device / grouping
Beitrag von: justme1968 am 08 Juni 2015, 18:26:51
you can use webCmd to configure the slider and drop down.

have a look at readingProxy and the color lamp examples in the current fhem.cfg.demo. multiple inputs are a little easier with readingProxy than a regular dummy. there is also a dmx control example in the wiki.

readingsGroup would allow a visual grouping of different devices there are lots of examples in the wiki.

regarding space usage: readingsGroup can be collapsed and expanded if needed.
Titel: Antw:Creating a new device / grouping
Beitrag von: andyclimb am 09 Juni 2015, 23:59:54
Ah readings proxy might help...

actually what i've done that is not too intensive is to create a load of dummies, then have a user readings that makes the command, a notify that passes the command to a dummy that is paired with a MQTT_BRIDGE.  This works well apart from 1 thing.  I have a bunch of modes... about 28 different light effects... I can pass text i the form "mode=fancy light mode 1"  or "mode=1".  fhem does not like spaces in the commands as it puts them into different event parts...

Question...

Can I have a setList that displays the text... but then sends the number... this would fix it for me! 

many thanks

Titel: Antw:Creating a new device / grouping
Beitrag von: justme1968 am 10 Juni 2015, 00:05:05
that should be possible with eventMap in a normal dummy or with the setFn in readingsProxy.
Titel: Antw:Creating a new device / grouping
Beitrag von: andyclimb am 10 Juni 2015, 00:28:39
thank you.  that works if i map say 1:xyz... but where I'm really running into trouble is with spaces...

here is what i have in the setList..

state:Off Rainbow Color Chase Rainbow,Fade,AdaLight,test,Looparound,Pick Random,Fade in Fade Out,Cool Blobs,UDP,Rainbow Cycle,Spiral,Squares2,Squares Random,Test4,Squares,EQ1,Random Colour, Random Function, Art-Net, HSV Top Bottom, Linear Top Bottom, Single Colour Fade, Random Colour Fade, HSIcycle

but every space is made into a separate item in the list.  so not quite what i want... from the commandref i thought that it is a comma separated list! 

any ideas?
Titel: Antw:Creating a new device / grouping
Beitrag von: andyclimb am 10 Juni 2015, 00:55:22
now I'm confused...
This is my setlist.  i took the spaces out
state:Off,Rainbow,Color,Chase-Rainbow,Fade,AdaLight,test,Looparound,Pick-Random,Fade-in-Fade-Out,Cool-Blobs,UDP,Rainbow-Cycle,Spiral,Squares2,Squares-Random,Test4,Squares,EQ1,Random-Colour,Random-Function,Art-Net,HSV-Top-Bottom,Linear-Top-Bottom,Single-Colour-Fade,Random-Colour-Fade,HSIcycle
This is my eventMap
Off:0 Rainbow:1 Color:2 Chase-Rainbow:3 Fade:4 AdaLight:5 test:6 Looparound:7 Pick-Random:8 Fade-in-Fade-Out:9 Cool-Blobs:10 UDP:11 Rainbow-Cycle:12 Spiral:13 Squares2:14 Squares-Random:15 Test4:16 Squares:17 EQ1:18 Random-Colour:19 Random-Function:20 Art-Net:21 HSV-Top-Bottom:22 Linear-Top-Bottom:23 Single-Colour-Fade:24 Random-Colour-Fade:25 HSIcycle:26

The results are inconsistent..
Off -> 0
Rainbow -> 1
Chase-Rainbow -> Chase-1
Fade -> 4
Adalight -> 5
...
Pick-Random -> 8
Fade-in-Fade-Out -> 4-in-Fade-Out

so what is going on and why do some, but not all give partial hits... (i think it is because it is matching the fade defined earlier.)  How can i stop this?
Titel: Antw:Creating a new device / grouping
Beitrag von: andyclimb am 10 Juni 2015, 15:34:43
In addition to the problem above I'm struggling to get the eventmap to work. 

I'm now using readings proxy as it is a simpler way to get things working and i'm almost there.

ReadingsProxy --> MQTT_DEVICE  --> MQTT message. 

For my effects i want a bunch of descriptions for the effect... as in my post above. (red mood blobs, green mood blobs, flashing headache)  and have the map to 1 2 3 respectively.  I was the text to appear in the drop down box (which i have), but then when i select an option it sends a 1, or 2, or 3 out via MQTT.  The event map works as a reading in them, but the value sent out is still the old text.  is there a way around this.

Also it seems that EventMap ignores the - ..  so words with a dash are partially found and replace.  as in my above post.

im so close....
Titel: Antw:Creating a new device / grouping
Beitrag von: rudolfkoenig am 10 Juni 2015, 15:40:42
There is a new, more complex eventMap variant you might try.
Titel: Antw:Creating a new device / grouping
Beitrag von: andyclimb am 10 Juni 2015, 16:36:05
is that the explicit variant... in attr store eventMap { dev=>{"on"=>"open"}, usr=>{"open"=>"on"} }

However, regardless.  will this one actually change what is outputted via MQTT.  The other event map does not. 

also...

I have this as my event map,
{ dev=>{"1"=>"effect1"}, usr=>{"1"=>"effect1"} } or
{ dev=>{"1"=>"effect1"} } or
{ usr=>{"1"=>"effect1"} }

created from the example on the commandref. 

I get this as an error
syntax error at (eval 56459) line 1, near "">{"effect1" in the text box for the device.
Now I'm a bit confused...
Titel: Antw:Creating a new device / grouping
Beitrag von: justme1968 am 10 Juni 2015, 16:40:26
i have not used the new format but i think you should probably use the strings that should be send in the setList and use the event map only to map these to the display values in the frontend.
Titel: Antw:Creating a new device / grouping
Beitrag von: andyclimb am 10 Juni 2015, 17:29:36
i tried that, but the problem is you are then blindly selecting 1 and 2, without knowing what they mean.  Are you aware of a method of doing it that way round?
Titel: Antw:Creating a new device / grouping
Beitrag von: andyclimb am 10 Juni 2015, 17:32:11
if i can't have numbers then i need to use spaces in the list, which i also can't seem to do.. i've tried lots of ways.  Can I escape spaces in setList?
Titel: Antw:Creating a new device / grouping
Beitrag von: justme1968 am 10 Juni 2015, 17:44:53
the problem with spaces is that a command containing spaces will always interpreted as a command followed by one or more parameters.

so you have to take the parameters into account.
Titel: Antw:Creating a new device / grouping
Beitrag von: andyclimb am 11 Juni 2015, 09:17:36
so is there no way of escaping spaces in fhem?  if so do you have an example?
Titel: Antw:Creating a new device / grouping
Beitrag von: justme1968 am 11 Juni 2015, 09:22:37
you don't have to escape them.

if you use readingsProxy just evaluate $ARGS in addition to $CMD so die example random, random function and random color are the same command wird an additional optional parameter.
Titel: Antw:Creating a new device / grouping
Beitrag von: andyclimb am 19 Juni 2015, 17:57:04
So I've re-written my ESP8266 code to get rid of spaces, and use MQTT topics instead.  I am almost there. 

One simple problem remains.

I'm using an MQTT_DEVICE that listens to and pushes out MQTT messages to my "DEVICE"  I have several publishSet_timer attr set.  So for example i want to publish to "devicename/mode" and set it to on or off.  this works fine.. I can issue the command "set mqtt_test2 mode off" and my lights go off. 

The problem now comes when i want a ReadingsProxy to control it all.   I need on for mode on/off, one for mode effect, one for brightness, one for timer etc.  I'd also like a hyperlink there to take me to the main page..

What I want is a switch on the proxy reading, a bulb that when i click it will toggle the light on/off.... BUT... I can ONLY get a drop down box to actually work..
attr XYZ setList mode:on,off
attr webCmd mode


This works, but it does not give me a switch.  I have tried many permutations, and all have failed! 
Titel: Antw:Creating a new device / grouping
Beitrag von: justme1968 am 19 Juni 2015, 18:00:58
to habe commands executed for a click in the icon you have to use the devStateIcon attribute.

see for example here: http://forum.fhem.de/index.php/topic,12080.msg71651.html#msg71651
Titel: Antw:Creating a new device / grouping
Beitrag von: andyclimb am 19 Juni 2015, 18:23:46
mmm.. not quite

on:on:mode off:off:mode

does work.  but if i click the icon i get a pop up that appears, like the one for room choice, and that has a drop down box.. 

I just want a lightbulb..  the issue is that is must be attached to mode:  if i do not have mode:on,off in set list then nothing ever happens?
Titel: Antw:Creating a new device / grouping
Beitrag von: justme1968 am 19 Juni 2015, 18:27:37
und mode is a commands that takes a parameter then a popup will apear.

if you just want on an and off then you should have a setList with on and off.

probably you can also use eventMap but only on and off should be much simpler.
Titel: Antw:Creating a new device / grouping
Beitrag von: andyclimb am 19 Juni 2015, 20:26:16
This is what I have been trying.  for several days now.  unless I have mode:on,off in the event map the command is NOT passed to the MQTT_DEVICE, as it is mapped to the reading mode. 

This mode, has to be identical to the reading that is is mapped to.. for example a readings proxy mapped to reading XYZ on MQTT_DEVICE ABC, must have  a setlist XYZ:a,b,c,d for it to be passed.  i've tried multiple variations, but cannot get it to work any other way. 
Titel: Antw:Creating a new device / grouping
Beitrag von: justme1968 am 19 Juni 2015, 20:56:42
you can change the command in the setFn. the command from the setList of the readingsProxy does not hate to be identical to the command that is passed to the parent device.

define <proxy> readingsProxy <parent>:mode
attr <proxy> setList on off
attr <proxy> devStateIcon on:on:off off:off:on
attr <proxy> setFn {"mode $VALUE"}


this will turn the simple on and off commands of the readings proxy into an set mode on/off command for the parent device.
Titel: Antw:Creating a new device / grouping
Beitrag von: andyclimb am 19 Juni 2015, 22:04:37
I really appreciate the help.  unfortunately that does not work.

define testproxy readingsProxy mqtt_test2:mode
attr testproxy setList on off
attr testproxy devStateIcon on:on:off off:off:on
attr testproxy setFn {"mode $VALUE"}


this is copied from my them cfg, so it is exactly what i have.   from my post earlier the command needs to be mode, with this code the command is still on and off, which does not work?

any other ideas?

And thank you for helping!

Titel: Antw:Creating a new device / grouping
Beitrag von: justme1968 am 19 Juni 2015, 22:10:28
sorry. my copy&paste mistake.

setFn hast to be:attr test proxy setFn {"mode $CMD"}

Titel: Antw:Creating a new device / grouping
Beitrag von: andyclimb am 19 Juni 2015, 22:32:21
GENIUS!  It worked!!!!
Titel: Antw:Creating a new device / grouping
Beitrag von: andyclimb am 19 Juni 2015, 22:32:58
THANK YOU
Titel: Antw:Creating a new device / grouping
Beitrag von: justme1968 am 19 Juni 2015, 22:34:12
you're welcome
Titel: Antw:Creating a new device / grouping
Beitrag von: andyclimb am 20 Juni 2015, 13:30:20
I've got another question, for SUPERSTAR bonus points!!!!!! 

All this is to control some lamps that I've made using an ESP8266, and WS2812 LEDs.  They look awesome!  I've not got on/off, brightness, and speed control....  BUT...  These lamps have modes or effects.... I've basically decided that each mode will have to be one word, as fhem really does not like spaces... However, having to type out the list every time, especially as there is a lot of change... is a pain..  i have 3 lights already. 

What I would like to do is have my device, publish a list of effects that it has to say device/effectslist "a,b,c,d" and then have fhem pick that up, and use it as the list of options for the readings proxy lamp3:effect.  Is this possible...? would be absolutely amazing...  I'm suspecting getList attribute, but i've tried a few things and get nothing to work

plus.. is there a way to list a URL there? (OK scratch that, figured it out... )  ValveFn = {"<a href='http://$VALUE' target="_blank">$VALUE</a>"}
Titel: Antw:Creating a new device / grouping
Beitrag von: justme1968 am 20 Juni 2015, 13:48:42
of course this is possible...

there is not really a problem with spaces but a space means that you have a command with one or more additional parameter(s).

if you have an automated way to get the list of effects you can set the setList from your code. how to do this depends on the source of this list. i don't know mqtt but if the push results in an fhem event you can just set the setList from a notify.

you can also set an attribute for multiple devices at the same time.attr myLamp.* setList ...see devspec in the commanders for all possible ways to do this.

getList and getFn ist for get commands. like setList and setFn is for set commands.
Titel: Antw:Creating a new device / grouping
Beitrag von: andyclimb am 20 Juni 2015, 15:38:10
ah of course, I did not think of a notify!   8)

so...  that works like a charm.  here is what I have... and this works. 

mqtt_lamp3:effectlist.* attr mqtt_lamp3_proxy_effect setList $EVTPART1

Is there a way to write a notify for a specific device type...  and a Reading then pass this on to a readingsProxy for that device..  here is my example so far

TYPE=MQTT_DEVICE:effectlist.* attr mqtt_$NAME_proxy_effect setList $EVTPART1

but this does not work.
Titel: Antw:Creating a new device / grouping
Beitrag von: justme1968 am 20 Juni 2015, 16:23:09
devspec works by first selecting a group of devices by regex and then appending :FILTER=... reduce the regex result by filtering out some devices

to set the attr it should be something like this:attr .*effectlist.*:FILTER=TYPE=MQTT_DEVICE setList xxx

to use $name you have to switch to the perl level and use something like this:{fhem("attr .*effectlist.*:FILTER=TYPE=MQTT_DEVICE mqtt_${name}_proxy_effect setList $EVTPART1")}
Titel: Antw:Creating a new device / grouping
Beitrag von: andyclimb am 20 Juni 2015, 18:01:39
mmm, not having much luck with that.. These are the REGEXP for a notify....

.*effectlist.* set lamp on  this works, and turns the lamp on. 
.*effectlist.*:FILTER=TYPE=MQTT_DEVICE set lamp on This does not work, so the filter is not working 

2)

.*effectlist.*  {fhem("attr ${name}_proxy_effect setList $EVTPART1")} This code picks up the change in effect list, in the device mqtt_lamp3 as above.. but fails to set the attribute to device mqtt_lamp_proxy_effect?

?