# Sonoff trigger with Webhooks

**URL:** <https://community.openhab.org/t/sonoff-trigger-with-webhooks/74890>\
**Category:** Off-Topic\
**Created:** [May 21, 2019, 2:42pm UTC](https://community.openhab.org/t/sonoff-trigger-with-webhooks/74890 "2019-05-21T14:42:31Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![MariusMitrin](https://community.openhab.org/letter_avatar_proxy/v4/letter/m/90ced4/32.png) [@MariusMitrin](https://community.openhab.org/u/MariusMitrin)\
**Post date:** [May 21, 2019, 2:42pm UTC](https://community.openhab.org/t/sonoff-trigger-with-webhooks/74890/1 "2019-05-21T14:42:31Z")

</div>

**Platform information:**

```
Hardware: Rasperry Pi 3
OS: Noobs
openjdk version “1.8.0_212”

```

**Issue of the topic:**  
Hello again!  
I want to use my Sonoff state as an external trigger to control another device, a Zigbee shader from Orvibo, that uses the app named Homenate. Basically, I want to have 2 switches wireless switches that control my shader through Webhooks and IFTTT. Sorry if I didn’t make myself clear so far.  
I am running into some troubles and I can’t see where is my mistake. First of all I made my sonoff switch to work, I can see the state and also can publish commands. The problem is when I add a group to my item file, it doesn’t recognize my items anymore  
**My files:**  
**ifttt\_trigger.rules**

```csv
rule "Send IFTTT Notification for Sonoff in Specific Group"

    when
        // Assign all sensor that will require notification together in one gorup
        Item gTrigger_Notification received update

    then
        // IFTTT parameters
        var String ifttt_key = "ihHjhXgJH7LkBYffXr0-UhnM_O7EVdxuR7C3UoBKC_g"
        var String ifttt_event = "Sonoff_Trigger"
        var String ifttt_url = "https://maker.ifttt.com/trigger/" + ifttt_event + "/with/key/" + ifttt_key
        var String notification_json

        // Get the last item that was updated
        var lastItem = gTrigger_Notification.members.sortBy[lastUpdate].last
        // Avoid sending the alert if the state didn't change
        // Compare state before update and now
        var lastState = lastItem.historicState(lastItem.lastUpdate.toDateTime.minusSeconds(1))

        //Check if last state is different than the current state. Zwave sensors send status reports on predefined intervals. This will trigger lastUpdate filed regard$
        if (lastState.state != lastItem.state) {
            notification_json = '{"value1":"' + lastItem.name + '","value2":"' + lastItem.state + '"}'
            sendHttpPostRequest(ifttt_url, "application/json", notification_json)
            logInfo("IFTT", "IFTTT: ALARM - " + lastItem.name + " changed state from: " + lastState.state + " to: " + lastItem.state)
        }
        else {
            // State didn't changed, supress the notification
            logInfo("IFFT", "IFFT: SUPPRESED - " + lastItem.name + " changed state from: " + lastState.state + " to: " + lastItem.state)
        }

end

```

**home.items**

```csv
Switch Sonoff1 "Sonoff_1" { mqtt=">[broker:house/cmnd/house-light-1/POWER:command:*:default],<[broker:house/stat/house-light-1/POWER:state:*]"}
Group gTrigger_Notification
String State1sonoff "State_1:[%s]" (gTrigger_Notification) { mqtt="<[broker:house/stat/house-light-1/power:state:default]"}

```

**home.sitemaps**

```csv
sitemap home label="Sonoff Switches" //creez o casa numita Sonoff Switches
{
       Frame label="Camera test" //creez camera test
       {
                 Switch item=Sonoff1 //adaug un item in camera test
                                      //itemele trebuie create in fisierul .item
                 Text item=State1sonoff
                 Text item=Sonoff-basic-1
       }
}

```

**rrd4j.persist**

```csv
Strategies {
    // for rrd charts, we need a cron strategy
    everyMinute : "0 * * * * ?"
}
Items {
    gTrigger_Notification* : strategy = everyUpdate, everyMinute, restoreOnStartup
}

```

---

<div class="post-metadata">

**Author:** ![rossko57](https://community.openhab.org/user_avatar/community.openhab.org/rossko57/32/70263_2.png) [@rossko57](https://community.openhab.org/u/rossko57)\
**Post date:** [May 21, 2019, 4:13pm UTC](https://community.openhab.org/t/sonoff-trigger-with-webhooks/74890/2 "2019-05-21T16:13:12Z")

</div>

> [@MariusMitrin](#):
>
> it doesn’t recognize my items anymore

What “it”, what does this mean?

When rules don’t run as expected, or when editing rules and items files, it is wise to look in `openhab.log`

This thread looks related

> [@members.sortBy\[lastUpdate\].last does not work](https://community.openhab.org/t/members-sortby-lastupdate-last-does-not-work/35674/4):
>
> All members of gAllAlarmSensors must have a state (i.e. they cannot be NULL) and they all must be persisted by your default persistence or else lastUpdate returns null. You can filter these problem items out using: val sensor = gAllAlarmSensors. members.filter[sensor | sensor.lastUpdate != null].sortBy[lastUpdate].last if(sensor == null) logWarn("FILE", "Something is amiss, no Item has a valid lastUpdate!")

although you could perhaps work with **Member of** group rule triggering instead

> [@Design Pattern: Working with Groups in Rules](https://community.openhab.org/t/design-pattern-working-with-groups-in-rules/20512):
>
> Edit: Updates for OH 4, inclusion of JS Scripting and Blockly examples, removed the doors example as it’s superfluous. Please see [Design Pattern: What is a Design Pattern and How Do I Use Them](https://community.openhab.org/t/design-pattern-what-is-a-design-pattern-and-how-do-i-use-them/40319) for how to read and use DPs. Problem Statement One powerful way to consolidate code in rules is to use array/list manipulation operations on the members of a Group. For example, filter down to just those members that are ON, get a list of the labels of those Items that are NULL, etc. Concept T…

---

<div class="post-metadata">

**Author:** ![MariusMitrin](https://community.openhab.org/letter_avatar_proxy/v4/letter/m/90ced4/32.png) [@MariusMitrin](https://community.openhab.org/u/MariusMitrin)\
**Post date:** [May 23, 2019, 8:39am UTC](https://community.openhab.org/t/sonoff-trigger-with-webhooks/74890/3 "2019-05-23T08:39:57Z")

</div>

The sitemap doesn’t recognize my items. I managed to get the log to see the errors.  
This happens when I try to use my Sonoff switch from my sitemap:

```csv
2019-05-23 11:34:29.603 [INFO] [rest.core.internal.item.ItemResource] - Received HTTP POST request at 'items/Sonoff1' for the unknown item 'Sonoff1'.

```

This is the error I get when I add the group gNotification:

```csv
2019-05-23 11:33:58.316 [ERROR] [ui.internal.items.ItemUIRegistryImpl] - Cannot retrieve item 'Sonoff1' for widget org.eclipse.smarthome.model.sitemap.Switch
2019-05-23 11:33:58.320 [ERROR] [ui.internal.items.ItemUIRegistryImpl] - Cannot retrieve item for widget org.eclipse.smarthome.model.sitemap.Switch
2019-05-23 11:33:58.323 [ERROR] [ui.internal.items.ItemUIRegistryImpl] - Cannot retrieve item 'Sonoff1' for widget org.eclipse.smarthome.model.sitemap.Switch
2019-05-23 11:33:58.326 [ERROR] [ui.internal.items.ItemUIRegistryImpl] - Cannot retrieve item 'Sonoff1' for widget org.eclipse.smarthome.model.sitemap.Switch
2019-05-23 11:33:58.329 [ERROR] [ui.internal.items.ItemUIRegistryImpl] - Cannot retrieve item 'Sonoff1' for widget org.eclipse.smarthome.model.sitemap.Switch
2019-05-23 11:33:58.333 [ERROR] [ui.internal.items.ItemUIRegistryImpl] - Cannot retrieve item for widget org.eclipse.smarthome.model.sitemap.Text
2019-05-23 11:33:58.336 [ERROR] [ui.internal.items.ItemUIRegistryImpl] - Cannot retrieve item 'State1sonoff' for widget org.eclipse.smarthome.model.sitemap.Text
2019-05-23 11:33:58.340 [ERROR] [ui.internal.items.ItemUIRegistryImpl] - Cannot retrieve item 'State1sonoff' for widget org.eclipse.smarthome.model.sitemap.Text
2019-05-23 11:33:58.343 [ERROR] [ui.internal.items.ItemUIRegistryImpl] - Cannot retrieve item 'State1sonoff' for widget org.eclipse.smarthome.model.sitemap.Text
2019-05-23 11:33:58.347 [ERROR] [ui.internal.items.ItemUIRegistryImpl] - Cannot retrieve item for widget org.eclipse.smarthome.model.sitemap.Text
2019-05-23 11:33:58.350 [ERROR] [ui.internal.items.ItemUIRegistryImpl] - Cannot retrieve item 'Sonoffbasic1' for widget org.eclipse.smarthome.model.sitemap.Text
2019-05-23 11:33:58.353 [ERROR] [ui.internal.items.ItemUIRegistryImpl] - Cannot retrieve item 'Sonoffbasic1' for widget org.eclipse.smarthome.model.sitemap.Text
2019-05-23 11:33:58.356 [ERROR] [ui.internal.items.ItemUIRegistryImpl] - Cannot retrieve item 'Sonoffbasic1' for widget org.eclipse.smarthome.model.sitemap.Text
2019-05-23 11:33:59.793 [INFO] [rest.core.internal.item.ItemResource] - Received HTTP POST request at 'items/Sonoff1' for the unknown item 'Sonoff1'.
2019-05-23 11:34:03.421 [INFO] [rest.core.internal.item.ItemResource] - Received HTTP POST request at 'items/Sonoff1' for the unknown item 'Sonoff1'.

```

---

<div class="post-metadata">

**Author:** ![rossko57](https://community.openhab.org/user_avatar/community.openhab.org/rossko57/32/70263_2.png) [@rossko57](https://community.openhab.org/u/rossko57)\
**Post date:** [May 23, 2019, 10:26am UTC](https://community.openhab.org/t/sonoff-trigger-with-webhooks/74890/4 "2019-05-23T10:26:32Z")

</div>

> [@MariusMitrin](#):
>
> for the unknown item ‘Sonoff1’

Okay, so these Items cannot be found by name in openHAB.  
Item names are case sensitive, but your items file and sitemap do appear to match.

If there is a problem with the syntax in an `xxx.items` file, it may not load any of the Items in that file, so that looks like a good place to look at.

At boot time, or when you edit the items file, you should see a message in openhab.log like

```csv
... [el.core.internal.ModelRepositoryImpl] - Loading model 'home.items'

```

If there is something wrong with it, error message will follow.

If you don’t see the loading message, the file isn’t getting seen. Check folder location.
