Can't initialize string variable

openhab2
Tags: #<Tag:0x00007fe058257930>

(JustAProgrammer) #1

So I want to update a String (which shows the current status of my alexa (installed on a Raspi)) by rules:
.items:
String AlexaPi_Ping "Aktueller Status" {channel="amazonechocontrol:echo:account1:echo1"}
.rules:
`
//Zeigt den Aktuellen Status von jedem Alexa Gerät

rule “Online/Offline Status AlexaPi”
when Item AlexaPi changed from ON to OFF
then
logInfo(“INFO”,“Wohnzimmer Echo wurde ausgeschaltet”)
AlexaPi_Ping.postUpdate(“ONLINE”)
end

rule “Online/Offline Status AlexaPi”
when Item AlexaPi changed from ON to OFF
then
logInfo(“INFO”,“Wohnzimmer Echo wurde ausgeschaltet”)
AlexaPi_Ping.postUpdate(“OFFLINE”)
end
`
But it doesn’t change anything in my .sitemap.
Do I miss something?


(Vincent Regaud) #2

What is the definition of the item AlexaPi?
What does the channel: amazonechocontrol:echo:account1:echo1 do?

Please use the code fences, thanks.


(JustAProgrammer) #3

Thanks for your answer.
AlexaPi is the Paper UI definition of the AVS Device
I don’t know it exactly, just copy/pasted it.
It’s not defined in the PaperUI…
looked for something like this a while lol, thank you!


(Udo Hartmann) #4

Both rules have an identical trigger.
Are you sure that it is correct to use postUpdate() instead of sendCommand() (which would be populated to amazonechocontrol)
Would be more suitable to do this in one rule:

rule “Online/Offline Status AlexaPi”
when 
    Item AlexaPi changed 
then
    if(AlexaPi.state == ON) {
        logInfo("INFO","Wohnzimmer Echo wurde eingeschaltet.")
        AlexaPi_Ping.postUpdate("ONLINE")
    } else {
        logInfo("INFO","Wohnzimmer Echo wurde ausgeschaltet.")
        AlexaPi_Ping.sendCommand("OFFLINE")
    }
end

less readable, but also correct and somewhat shorter:

rule “Online/Offline Status AlexaPi”
when 
    Item AlexaPi changed 
then
    logInfo("INFO","Wohnzimmer Echo wurde {}geschaltet.", if(AlexaPi.state == ON) "ein" else "aus")
    AlexaPi_Ping.sendCommand(AlexaPi.state.toString + "LINE")
end

Regarding the sitemap: You don’t need any rule for the sitemap, just use a mapping:
items/*.items

Switch AlexaPi "Alexa Pi ist [MAP(pingstate.map):%s]" {...}

transformations/pingstate.map

OFF = OFFLINE
ON = ONLINE
NULL = -

sitemaps/*.sitemap

Text item=AlexaPi

(JustAProgrammer) #5

Hello Udo,
Thanks a lot for the complete Code, I appreciate the Time you’ve invested.
But it doesnt work. As I understood(I didn’t work with the .map folder yet) it should show “NULL” but it simply shows “-”.
Could I just use the network binding and send a simple ping every 10 minutes to check the state of my AlexaPi?
I guess that would be the most simple solution.
Thanks in advantage
Nico F.


(Vincent Regaud) #6

In the sitemaps NULL shows as - anyway

You could do that, I thinks the default ping period is 1 minute


(JustAProgrammer) #7

Yeah, so a Ping isn’t an option since my Raspberry is always pingable, if the AVS is running or not. Didn’t think about that smh.
should work with my Echo, but I actually want to interact with this item of the PaperUI:
AlexaBinding
Is there a way to interact with the status of the PaperUI thing in a .rules file?
Probably would be the easiest and most stable thing to do.


(Sascha Billian) #8
var status = ThingAction.getThingStatusInfo("amazonechocontrol:unknown:5593f08c:b4d3b712bbl")

Should report the status of the thing. This you can use to update an item that should represent the status in your UI


(JustAProgrammer) #9

Thank you my man, that was the answer or method I’ve been looking for.