[SOLVED] Why does my FRITZ! Smart Home Template not apply?

I am using the latest version (2.4.0) on a Raspberry Pi and I am using the AVM FRITZ! Binding with several FRITZ!DECT 200 items. So far so good everything works fine.

I also integrated my items with HomeKit and it works as well.

Here I read it is possible to apply smart home templates.

Therefore I created a rule to turn it on and another one to turn it off. Turn on does not seem to work and the question is also how to turn it off?

This is my item for it, I just created a dummy item for it and in the iOS Home app I am able to toggle it:

String ApplyTemplate "Apply template" { channel="avmfritz:fritzbox:1:apply_template" }

Switch HK_Urlaubsmodus "Urlaubsmodus" <light> (gUrlaubsmodus) [ "Lighting" ]

These are my rules:

rule "Urlaubsmodus An"
when
    Item HK_Urlaubsmodus changed from OFF to ON
then
    ApplyTemplate.sendCommand("tmp2D5DCF-39722FC0E")
    logInfo("demo", "Urlaubsmodus an")
end

rule "Urlaubsmodus Aus"
when
    Item HK_Urlaubsmodus changed from ON to OFF
then
    ApplyTemplate.sendCommand("")
    logInfo("demo", "Urlaubsmodus aus")
end

And this is the output in the log:

What do I need to do to be able to turn on/off the template? Or am I completely wrong?

Hi Philipp,

First of all I am sorry to say but the FRITZ! Smart Home Template feature is not part of the 2.4.0 binding version. It has been introduced later. I am afraid have to upgrade your OH to milestone build or wait for the next release.

One note to your approach. It is not possible to reset a previous applied template or switch back to a default template. I already was in contact with AVM to clarify but unfortunately they will not implement support for that. Thus you have to set-up a workaround for it. Create a new template via FRITZ!OS and call it e.g. “Vorlage löschen”. Add all devices of your choice and check the box “Automatische Schaltung löschen” (see screenshot). Look-up the template id and apply it in case you want to reset your template.

In the meantime I found a solution for accessing the StateOptions of an item via rules:

demo.items:

String fritzFritzBoxApplyTemplate "Vorlage anwenden" {
    channel="avmfritz:fritzbox:<THING_ID>:apply_template"
}
Switch TESTSwitch

demo.rule:

rule "FRITZ!Box - print templates"
when
    Item TESTSwitch changed to ON
then
    fritzFritzBoxApplyTemplate.getStateDescription.getOptions.forEach[option |
        logInfo("fritz", "Template: [name='{}', id='{}']", option.getLabel, option.getValue)
//        if( "Sonnenuntergang".equals(option.getLabel) ) {
//            logInfo("fritz", "Apply template: {}", option.getLabel)
//            fritzFritzBoxApplyTemplate.sendCommand(option.getValue)
//            // do other stuff
//        }
    ]
end
2019-03-21 13:47:21.688 [INFO ] [eclipse.smarthome.model.script.fritz] - Template: [name='Sonnenuntergang', id='tmpA5AD9A-395AXXXXX']
2019-03-21 13:47:21.701 [INFO ] [eclipse.smarthome.model.script.fritz] - Template: [name='Vorlage löschen', id='tmpA5AD9A-3966YYYYY']

Ok. Thanks for clarification, Christoph. The solution sounds good. Since my installation is just so stable I don’t dare to upgrade. I think I will wait for the next release. Can I somehow recognize in the documentation which features are part of the current release and which are not?

Fair enough.

In the top right corner of the documentation you can find a selection to choose between versions.

I made a backup of my openHABian image and I am going to install the needed update.

How do I do that? Is it the latest test build on openHABian (see screenshot below)?

I am not an openhabian expert. Have a look here. I think you have to go for the testing build - which afaik are the milestone builds.

Yes you are right, there I found the milestone builds:

openHAB_milestone

I installed 2.5.0.M1 Milestone Build. When I try to trigger the template I get the following error:

2019-05-06 20:24:56.389 [ERROR] [ntime.internal.engine.RuleEngineImpl] - Rule 'Urlaubsmodus An': cannot invoke method public java.util.List org.eclipse.smarthome.core.types.StateDescription.getOptions() on null

This is my item:

String fritzFritzBoxApplyTemplate "Apply template" { channel="avmfritz:fritzbox:1:apply_template" }
Switch HK_Urlaubsmodus "Urlaubsmodus" <light> (gUrlaubsmodus) [ "Lighting" ]

This is my rule:

rule "Urlaubsmodus An"
when
    Item HK_Urlaubsmodus changed to ON
then
    fritzFritzBoxApplyTemplate.getStateDescription.getOptions.forEach[option |
        logInfo("fritz", "Template: [name='{}', id='{}']", option.getLabel, option.getValue)
        if( "Urlaubsmodus starten".equals(option.getLabel) ) {
            logInfo("fritz", "Apply template: {}", option.getLabel)
            fritzFritzBoxApplyTemplate.sendCommand(option.getValue)
        }
    ]
end

rule "Urlaubsmodus Aus"
when
    Item HK_Urlaubsmodus changed to OFF
then
    fritzFritzBoxApplyTemplate.getStateDescription.getOptions.forEach[option |
        logInfo("fritz", "Template: [name='{}', id='{}']", option.getLabel, option.getValue)
        if( "Urlaubsmodus beenden".equals(option.getLabel) ) {
            logInfo("fritz", "Apply template: {}", option.getLabel)
            fritzFritzBoxApplyTemplate.sendCommand(option.getValue)
        }
    ]

These are my templates:

Do you know what is wrong here?

demo.items:

String fritzFritzBoxApplyTemplate "Vorlage anwenden" {
    channel="avmfritz:fritzbox:<THING_ID>:apply_template"
}
Switch TESTSwitch

How do I get the THING_ID to apply the template? I cannot see any new thing after update and re-scan for things in the AVM Fritz Binding. Is it the Fritz!Box ID? Like avmfritz:fritzbox:XXX_XXX_XXX_X? I don’t get the connection.

Hi Philipp,

Yes, the <THING_ID> is the FRITZ!Box id. If you added it via auto-discovery the I’d is similar to the IP address (: replaced by _). If you are using textual configuration it is the third value in the UID (e.g. “1” in the example from the documentation Bridge avmfritz:fritzbox:1).

Thanks for your help, Christoph. I use the auto discovery approach. But I always get the same error message:

2019-05-13 21:44:13.677 [ERROR] [ntime.internal.engine.RuleEngineImpl] - Rule 'Urlaubsmodus An': cannot invoke method public java.util.List org.eclipse.smarthome.core.types.StateDescription.getOptions() on null

When I use the template AIN the log looks like this, and it still does not work:

2019-05-13 21:32:28.904 [ome.event.ItemCommandEvent] - Item 'fritzFritzBoxApplyTemplate' received command tmp2D5DCF-39722FC0F
2019-05-13 21:32:28.942 [nt.ItemStatePredictedEvent] - fritzFritzBoxApplyTemplate predicted to become NULL

I assume the string fritzFritzBoxApplyTemplate does not get any connection. It looks like this:

String fritzFritzBoxApplyTemplate "Apply template" { channel="avmfritz:fritzbox:192_168_188_1:apply_template" }

My Fritz!Box thing looks like this:

FritzBoxThing

Do you have any idea? What can I do to trace it?

You can enable e.g. TRACE logging for the binding to find out if the request of the binding to the FRITZ!Box is successful. Do the following steps:

You maybe want to send it via PM to me to avoid leaking sensitive data.

Thanks for your help @cweitkamp. I could fix it by removing and adding the Fritz!Box thing again. Seems to be necessary after upgrading from 2.4.0 to 2.5.0 M1. To verify the paring is correct I checked if I can find my templates in the control section:

My logs look this when toggle the switch successfully:

2019-05-29 23:43:20.485 [INFO ] [eclipse.smarthome.model.script.fritz] - Apply template: Urlaubsmodus starten
==> /var/log/openhab2/events.log <==
2019-05-29 23:43:20.586 [ome.event.ItemCommandEvent] - Item ‘fritzFritzBoxApplyTemplate’ received command tmp2D5DCF-39722FC0F
2019-05-29 23:43:20.659 [nt.ItemStatePredictedEvent] - fritzFritzBoxApplyTemplate predicted to become tmp2D5DCF-39722FC0F
2019-05-29 23:43:20.769 [vent.ItemStateChangedEvent] - fritzFritzBoxApplyTemplate changed from UNDEF to tmp2D5DCF-39722FC0F
2019-05-29 23:43:20.795 [vent.ItemStateChangedEvent] - fritzFritzBoxApplyTemplate changed from tmp2D5DCF-39722FC0F to UNDEF

1 Like

:+1: You are welcome.