Property vs. Action vs. Event

(Lg Lindstrom) #1

Hi

Can anyone please explain the use cases for Property, Action and Event. I Don’t see any difference on them. How are they supposed to be used ?

0 Likes

(Martin Giger) #2

The are very much different things.

An action is something that can be triggered on a device.

An event is something the device reports as happening (so can not be triggered from the outside).

A property is a stateful field, which reflects a “property” of the device. If that state changes, the state is reflected in the API (resp. the gateway). If the property isn’t read only, the value of the property can be changed from the outside.

So they’re pretty much the common meaning of those terms, “property”, “action” and “event” in the eyes of the device/thing.

0 Likes

(Ben Francis) #3

Our Web Thing API specification describes them as follows:

  • The properties member is a map of Property objects which describe the attributes of the device.
  • The actions member is a map of Action objects which describe functions that can be carried out on a device. Actions are used when the setting of a property alone is not sufficient to affect a required change in state. This may be used to describe a function which takes a period of time to complete, manipulates multiple properties, or has a different outcome based on provided arguments or current state. An example might include a “fade” action which has a specified “duration”, a “sequence” action which triggers a sequence of flashing lights or a “toggle” action on a switch.
  • The events member is a map of Event objects which define the types of events which may be emitted by a device. Events can be used where subscribing to a change in property state is not sufficient. This may be used to monitor changes in multiple properties or events which describe something other than a property change. An example might be an event which is emitted when a device is about to reboot.
0 Likes

(Lg Lindstrom) #4

I understand what you are saying ( and actually have read it …)

But still everthing can be achieved using a property.

  • Starting a fade “action” can be done by writing a “fade string” to a property and the device interpretet the string and performs the “fade”
  • Sending a event to the gateway can be performed by setting a property and letting the adapter to interpretet it.

Looking at it from this point of view makes actions and events quite unnecessary. It is possible to solve everything with a property. Matter of fact, webthing-arduino haven’t even implemented action and events.

So, this said, Are the gateway treating Properties, Actions and Events in different ways ?

0 Likes

(Martin Giger) #5

A property has a persistent value, neither actions nor events have a persistent value, that’s the big reason why they’re not just properties. If you look at the API actions and events are very similar to properties, just cut down to what you need for those use cases.

0 Likes

(Ben Francis) #6

I agree that it can sometimes be difficult to decide when to use a property, action or event. We’ve tried to provide some guidelines in the spec, but it can still be unclear. For example iotschema.org specify a lot of actions for setting properties and events for reporting property changes which both seem redundant to me.

While it’s true that you can hack around most use cases just using properties, there are cases where actions or events are a more natural fit (e.g. actions which take time to complete or accept arguments or events which report an exception case or threshold of some kind).

Note that the data model of properties, actions and events is not something Mozilla defined - it comes from the W3C Thing Description specification which has been agreed upon by members of the W3C WoT Working Group.

0 Likes

(Lg Lindstrom) #7

Everything is “hackable” :grinning:

If the gateway supports properties, action and events with its visual behavior it would be more understandable.

For example:
If “fade” action is invoked from gateway, the “bubble” blinks until the fade process is finished.
or…
if a “overheated” event is sent from the gateway, the “bubble” gets a red background.

0 Likes

(Martin Giger) #8

The gateway does support all of these things. Actions and properties render differently. Actions are just a button. And events are shown as toast notifications and logged in an event log.

Properties and actions:

Event log:

1 Like

(Lg Lindstrom) #9

Perfect, but where are this documented ?
I’ve seen nothing about it, but maybe I am a poor reader ??

0 Likes

(Martin Giger) #10

I don’t think there’s full documentation of what the gateway does, which is understandable given that it’s just an experiment. The best way to learn about the gateway is to try it yourself.

The gateway also isn’t the only way one could consume the WoT API.

0 Likes

(Lg Lindstrom) #11

Try what ?
If you don’t know it exists, how are you supposed to try it out ? :smiley:

Anyhow, I think the best way to success is to have good documentation so you get many followers. But that’s my view.

0 Likes

(Martin Giger) #12

The gateway.
The entry point to the whole IoT project, https://iot.mozilla.org/ prominently features the gateway and how to install it.

0 Likes