Re: [mh] How to check for a separate object state change?
Richard F <[email protected]> Sat, 17 Aug 2024 15:48:55 +0100
| Newsgroups | gmane.comp.misc.misterhouse.user |
|---|---|
| Organization | Keynet Technology |
| Message-ID | <[email protected]> |
This is a multi-part message in MIME format.
--===============1040951386837749391==
Content-Type: multipart/alternative;
boundary="------------7H83WNUKN8Z0dIGvNYAl43hv"
Content-Language: en-GB
This is a multi-part message in MIME format.
--------------7H83WNUKN8Z0dIGvNYAl43hv
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: quoted-printable
I may also be missing something, but doesn't something like this do it...=
?
if ($state =3D state_changed $sensor1) {
$relay_control -> set ($state, 'sensor changed');
}
OR depending on what you need to manipulate
if ($state =3D state_changed $sensor1) {
if ($state eq 'open') {
$relay_control -> set (ON, 'sensor changed');
run_voice_cmd (...)
} elsif ($state eq 'closed') {
....
} else {
....etc
}
}
I have quite a lot of that sort of code, the format of which I picked up=20
from somewhere in ancient times. If it's looking for state_changed in=20
real time it has to be inline in the code, but I'm sure you knew that.=20
'Ternary' 1 liners like this are really handy to link items too. $secure =
=3D state $mode_security eq 'armed' ? 1 : 0;HTH
On 16/08/2024 22:35, H Plato wrote:
> Hi,
>
> I have a weeder interface that both monitors the state of my garage =
door (with a magnetic contact), and triggers open/closed with a relay. To=
match some of the newer garage door controls, I added a second magnetic =
switch to my door, so that I can know when it=E2=80=99s closed, opening, =
open, and closing.
>
> To simplify this, I was going to create a GarageDoor.pm item. However, =
I feel like i=E2=80=99m missing something super obvious, as I don=E2=80=99=
t see an easy way for a separate object to get triggered when it=E2=80=99=
s state changes. I want to do this:
>
> $garage_door =3D new Garage_Door($relay_control, $sensor1);
>
> if $sensor1 changes, then MH will change the $garage_door.
>
>
> I can =E2=80=98bruteforce=E2=80=99 this, by adding in a hook in the obj=
ect new sub:
>
> &::MainLoop_pre_add_hook( \&Garage_Door::check_for_data, 1, $self );
>
> with a sub in the object:
>
> sub check_for_data {
> my ($self) =3D @_;
>
> if state_changed ($self->sensor_object) {
> $self->set(=E2=80=9Csomething=E2=80=9D);
> }
> }
>
> but this seems overly complex, so thought I would check with the list t=
o see if there is a simpler way to do this.
>
>
> As an aside, there was some discussions earlier this year about an u=
pdated stable. I still think it=E2=80=99s a good idea, and I encourage ev=
eryone to update to master so we can find any issues. I=E2=80=99m almost =
done migrating my device modules to Home Assistant (with a connection bac=
k to MH through HA_Item), I=E2=80=99ve ran into a few hiccups with my spr=
inkler and nanoleaf that I need to resolve. I=E2=80=99ve also got a bit d=
istracted with other technical projects (like the garage door). However I=
think end of year is a good goal. Looking at sourceforge, the oldest MH =
release is 1.93 in 2000. 25 years shows how ahead-of-it=E2=80=99s-time MH=
was.
>
--------------7H83WNUKN8Z0dIGvNYAl43hv
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
<!DOCTYPE html>
<html>
<head>
<meta http-equiv=3D"Content-Type" content=3D"text/html; charset=3DUTF=
-8">
</head>
<body>
<p><font face=3D"Helvetica, Arial, sans-serif">I may also be missing
something, but doesn't something like this do it...?<br>
</font></p>
<pre>if ($state =3D state_changed $sensor1) {</pre>
<pre class=3D"moz-quote-pre" wrap=3D""> $relay_control -> set ($st=
ate, 'sensor changed');
</pre>
<pre><font face=3D"Helvetica, Arial, sans-serif">}
</font>
OR depending on what you need to manipulate
if ($state =3D state_changed $sensor1) {
if ($state eq 'open') {
$relay_control -> set (ON, 'sensor changed');
run_voice_cmd (...)
} elsif ($state eq 'closed') {
....
} else {
....etc
}
}
<font face=3D"Helvetica, Arial, sans-serif">I have quite a lot of that so=
rt of code, the format of which I picked up from somewhere in ancient tim=
es.
If it's looking for state_changed in real time it has to be inline in the=
code, but I'm sure you knew that.
'Ternary' 1 liners like this are really handy to link items too.
</font>$secure =3D state $mode_security eq 'armed' ? 1 : 0;<font
face=3D"Helvetica, Arial, sans-serif">
HTH
</font></pre>
<div class=3D"moz-cite-prefix">On 16/08/2024 22:35, H Plato wrote:<br=
>
</div>
<blockquote type=3D"cite"
cite=3D"mid:[email protected]">
<pre class=3D"moz-quote-pre" wrap=3D"">Hi,
I have a weeder interface that both monitors the state of my garage doo=
r (with a magnetic contact), and triggers open/closed with a relay. To ma=
tch some of the newer garage door controls, I added a second magnetic swi=
tch to my door, so that I can know when it=E2=80=99s closed, opening, ope=
n, and closing.=20
To simplify this, I was going to create a GarageDoor.pm item. However, I =
feel like i=E2=80=99m missing something super obvious, as I don=E2=80=99t=
see an easy way for a separate object to get triggered when it=E2=80=99s=
state changes. I want to do this:
$garage_door =3D new Garage_Door($relay_control, $sensor1);
if $sensor1 changes, then MH will change the $garage_door.
I can =E2=80=98bruteforce=E2=80=99 this, by adding in a hook in the objec=
t new sub:
&::MainLoop_pre_add_hook( \&Garage_Door::check_for_data, 1, $sel=
f );
with a sub in the object:
sub check_for_data {
my ($self) =3D @_;
if state_changed ($self->sensor_object) {
$self->set(=E2=80=9Csomething=E2=80=9D);
}
}
but this seems overly complex, so thought I would check with the list to =
see if there is a simpler way to do this.
As an aside, there was some discussions earlier this year about an upda=
ted stable. I still think it=E2=80=99s a good idea, and I encourage every=
one to update to master so we can find any issues. I=E2=80=99m almost don=
e migrating my device modules to Home Assistant (with a connection back t=
o MH through HA_Item), I=E2=80=99ve ran into a few hiccups with my sprink=
ler and nanoleaf that I need to resolve. I=E2=80=99ve also got a bit dist=
racted with other technical projects (like the garage door). However I th=
ink end of year is a good goal. Looking at sourceforge, the oldest MH rel=
ease is 1.93 in 2000. 25 years shows how ahead-of-it=E2=80=99s-time MH wa=
s.
</pre>
</blockquote>
</body>
</html>
--------------7H83WNUKN8Z0dIGvNYAl43hv--
--===============1040951386837749391==
Content-Type: text/plain; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Content-Disposition: inline
--===============1040951386837749391==
Content-Type: text/plain; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Content-Disposition: inline
________________________________________________________
To unsubscribe from this list, go to: https://lists.sourceforge.net/lists/listinfo/misterhouse-users
--===============1040951386837749391==--