Category Archives: Uncategorized

Analog Device Automation

I’ve got three Marpac white noise generators distributed around my bedroom.  It is a mild nuisance to have to walk around the room and switch each one’s state at the boundary of a sleep session.  And so I acquired an Aeotec “Smart Switch” for each one of them and an Aeotec “Minimote” to operate them under the yoke of my growing Home Assistant driven Z-Wave network.

I was a little bit muddled by the Minimote’s setup until I realized that you can use it either as a primary or secondary Z-Wave controller and it was the latter I wanted which entailed pressing the “Learn” button as opposed to the “Include” button when joining it to the existing network.  The other configuration was to set it to “Scene” mode vs “Group” mode, the former giving you two distinct “scenes” per button with a short and long press.

I only made one configuration change to the Smart Switches out of the box.  Specifically, I configured parameter 81, “Configure the state of the LED”, to “When the state of the Switch changes, the LED will follow the status (on/off) of its load, but the LED will turn off after 5 seconds.”  This provides useful visual telemetry without leaving you with glowing orbs in the room you’d like to be dark for sleeping.

There were some other bumps along the way…

The switches had some identity crises at the outset.  I started with node id 14, added one that became 19, and added another that became 21.  14 then disappeared and, I think, came back as 22.  Now 14, 19, and 22 seem to be the healthy ones and 21 is AWOL.  Things seem to work now, but I was a bit perplexed for a while, and not sure what exactly happened.  I would probably have to have been tracking raw device identifiers to truly understand.  Maybe I can do that forensically later.

Initially I imagined just using a single “scene” on the Minimote and invoking the “switch.toggle” service, but this was not fault tolerant, the failure mode being that if a hiccup in command distribution prevented all devices from receiving a broadcast then a subsequent toggle command would cause a subset of the switches to be on and a subset off.  Ugh.  So I’m consuming both of the “scenes” of one of the buttons to do an explicit “switch.turn_on” or “switch.turn_off” command.

Lastly, occasionally, as captured in the below video (listen closely and you hear two of the three devices switch off immediately), there is a bit of delay between button-press and response, but generally it is immediate.  This has me developing the suspicion that I am getting some network congestion. I modified configuration parameter 111, “Group 1 Interval”, to 60 for all of my MultiSensor devices to get them to submit reports every minute instead of what appeared to be an hourly out-of-the-box configuration.  Now I am getting the reports I want but possibly congestion once per minute.  Maybe I need a lower reporting frequency and some staggering?  I also note that this upped frequency sabotages having set the bedroom-located MultiSensors’ parameter 81, “LED report”, to “Disable” to prevent obnoxious blinking in response to the motion sensor, because the LED will also blink whenever it sends its period report.  UGH.  I ended up using the l337 hack of putting electrical tape over the LED in those devices.

group:
  smart_switches:
    name: "Smart Switches"
    entities:
      - switch.aeotec_zw096_smart_switch_6_switch
      - switch.aeotec_zw096_smart_switch_6_switch_2
      - switch.aeotec_zw096_smart_switch_6_switch_4
automation:
  - alias: Start White Noise
    trigger:
      platform: event
      event_type: zwave.scene_activated
      event_data:
        entity_id: zwave.aeotec_dsa03202_minimote
        scene_id: 1
    action:
      service: switch.turn_on
      entity_id: group.smart_switches
  - alias: Stop White Noise
    trigger:
      platform: event
      event_type: zwave.scene_activated
      event_data:
        entity_id: zwave.aeotec_dsa03202_minimote
        scene_id: 2
    action:
      service: switch.turn_off
      entity_id: group.smart_switches

 

Feline Loss Prevention

Bringing together a Raspberry Pi, Home Assistant, and an Aeotec ZWave Stick, Door/Window Sensor, and Siren, I’ve got the beginnings of something practical: an audio alert that will fire with escalating intensity when a door is left ajar long enough to risk a curious animal wandering out of the house.

The configuration is a little bit copy-pasta and a little bit inconsistent. I don’t yet know how much cleaner it can be with Home Assistant’s native faculties. That is a project for future Andrew. Today’s exercise was an exploration of the art of the possible.

automation:
  - alias: Rear Door Ajar Alarm Initiation
    trigger:
      platform:  state
      entity_id: binary_sensor.aeotec_zw112_door_window_sensor_6_sensor_2
      to: 'on'
      for:
        seconds: 5
    action:
      - service: zwave.set_config_parameter
        data:
          node_id:   13
          parameter: 37
          value:     "Sound 5 - Low Volume"
  - alias: Rear Door Ajar Alarm Escalation
    trigger:
      platform:  state
      entity_id: binary_sensor.aeotec_zw112_door_window_sensor_6_sensor_2
      to: 'on'
      for:
        seconds: 10
    action:
      - service: zwave.set_config_parameter
        data:
          node_id:   13
          parameter: 37
          value:     "Sound 4 - Low Volume"
  - alias: Rear Door Ajar Alarm Panic
    trigger:
      platform:  state
      entity_id: binary_sensor.aeotec_zw112_door_window_sensor_6_sensor_2
      to: 'on'
      for:
        seconds: 15
    action:
      - service: zwave.set_config_parameter
        data:
          node_id:   13
          parameter: 37
          value:     "Sound 3 - Low Volume"
  - alias: Rear Door Ajar Alarm Termination
    trigger:
      platform:  state
      entity_id: binary_sensor.aeotec_zw112_door_window_sensor_6_sensor_2
      to: 'off'
    action:
      - service:   switch.turn_off
        entity_id: switch.aeotec_zw080_siren_gen5_switch
  - alias: Front Door Ajar Alarm Initiation
    trigger:
      platform:  state
      entity_id: binary_sensor.aeotec_zw112_door_window_sensor_6_sensor
      to: 'on'
      for:
        seconds: 10
    action:
      - service: zwave.set_config_parameter
        data:
          node_id:   13
          parameter: 37
          value:     "Sound 5 - Low Volume"
  - alias: Front Door Ajar Alarm Escalation
    trigger:
      platform:  state
      entity_id: binary_sensor.aeotec_zw112_door_window_sensor_6_sensor
      to: 'on'
      for:
        seconds: 30
    action:
      - service: zwave.set_config_parameter
        data:
          node_id:   13
          parameter: 37
          value:     "Sound 4 - Low Volume"
  - alias: Front Door Ajar Alarm Panic
    trigger:
      platform:  state
      entity_id: binary_sensor.aeotec_zw112_door_window_sensor_6_sensor
      to: 'on'
      for:
        seconds: 60
    action:
      - service: zwave.set_config_parameter
        data:
          node_id:   13
          parameter: 37
          value:     "Sound 3 - Low Volume"
  - alias: Front Door Ajar Alarm Termination
    trigger:
      platform:  state
      entity_id: binary_sensor.aeotec_zw112_door_window_sensor_6_sensor
      to: 'off'
    action:
      - service:   switch.turn_off
        entity_id: switch.aeotec_zw080_siren_gen5_switch

Moar Home Automation

cat .homeassistant/configuration.yaml

group:
  den_lights:
    name: "Den Lights"
    entities:
      - light.hue_color_lamp_16
      - light.hue_color_lamp_18
      - light.hue_color_lamp_22

automation:
  - alias: Handle Back Door Open
    trigger:
      platform:  state
      entity_id: binary_sensor.aeotec_zw112_door_window_sensor_6_sensor_2
      to: 'on'
    action:
      - service:    light.turn_off
        entity_id:  group.den_lights
        data:
          transition: 3
      - service: zwave.set_config_parameter
        data:
          node_id:   12
          parameter: 40
          value:     "Fade out and fade in (Red)"
  - alias: Handle Back Door Open Alarm Reset
    trigger:
      platform:  state
      entity_id: binary_sensor.aeotec_zw112_door_window_sensor_6_sensor_2
      to: 'off'
      for:
        seconds: 5
    action:
      - service: zwave.set_config_parameter
        data:
          node_id:   12
          parameter: 40
          value:     "Fade out and fade in (Green)"

Order Of Operations

I’m all for justice and equality.  But can we agree that the following is a crappy algorithm for an organization to follow?

  1. receive allegations about employee misconduct
  2. punish employee
  3. thoroughly investigate veracity of allegations

Justice delayed is justice denied, but so, too, is justice rushed.

From the Washington Post

Minnesota Public Radio said it has retained an outside law firm to conduct an “independent investigation” into the allegations [about Garrison Keillor]. The station will stop distributing and broadcasting “The Writer’s Almanac,” a show Keillor still produced after retiring from “A Prairie Home Companion.” The latter show, which will be renamed, has been hosted by Chris Thile since Keillor’s retirement.

Shouldn’t the “independent investigation” have been given time to run its course before taking such drastic and public measures?  Let us have “speedy and public trials … by … impartial jur[ies]”, not mob justice, not witch hunts.

Home Monitoring Inaugural Foray

I have for some time been obsessive about instrumenting the software systems I build professionally.  I figure I might as well bring that level of rigor to my home’s function.  A colleague suggested that I look into sensors created by AeoTec and automation orchestrated by Home Assistant.  To that end I purchased a Raspberry Pi 3 to run HA, a Z-Stick to bridge the various devices to it, a Multi Sensor 6, and a Door/Window Sensor 6.  Those devices arrived last week and I spent a little time this weekend contriving to reach a “Hello, World” level of sophistication.

The following is essentially a collection of notes on the steps required and my reactions along the way, not a meaningful synthesis which will probably require several more weekends of tinkering to reach.

After booting up Raspbian, the following got me to a basic level of function (can’t promise there aren’t some ordering or redundancy issues):

 

  1. sudo apt-get update
  2. sudo apt-get upgrade
  3. sudo apt-get install python3-pip python3-dev
  4. sudo pip3 install –upgrade virtualenv
  5. sudo apt-get install python-virtualenv
  6. virtualenv –python=/usr/bin/python3.4 $HOME/homeassistant
  7. source $HOME/homeassistant/bin/activate
  8. pip3 install –upgrade homeassistant
  9. $HOME/homeassistant/bin/hass
  10. sudo apt-get install libudev-dev
  11. reboot
  12. [unplug/replug Z-Stick]
  13. ls -ltr /dev/tty* | tail -n 1
    • crw-rw—- 1 root dialout 166, 0 Nov 25 18:16 /dev/ttyACM0
  14. vi .homeassistant/configuration.yaml
    • zwave:
      • usb_path: /dev/ttyACM0

Ultimately I was able to access the web GUI at http://localhost:8123 with USB keyboard/mouse and HDMI direct access to the Pi.

The main fiddly bit was in 12-14 where you’re figuring out the device ID of the Z-Stick and then persisting that to your HA config.  You’ll also get burned along these lines if you follow the printed instructions with the AeoTec devices which counsel you to unplug the Z-Stick as step one of putting it into “Inclusion Mode” to add devices to the network.  You actually want to be engaging “Inclusion Mode” via the HA GUI, firstly to ensure that HA acquires all information possible from the pairing process, and secondly so that the device does not pop back up under the /dev file system with a different name that does not match your config.

The Multi Sensor mostly worked out of the box with HA.  The Door/Window Sensor, however, created a fair deal of frustration.

Specifically, the latter would stay stuck in the “On” state.  The .homeassistant/OZW_Log.txt log file was somewhat elucidating of the problem in conjunction with some Googling.  Out of the box, the sensor sends a “Basic Set” event when the sensor’s state changes, but you need it to send a “Binary Sensor Report” for HA to behave as you’d expect.  Not only was figuring out the source of the trouble painful, but so was figuring out the resolution.

HomeAssistant wrote a zwcfg_0xf7a9395f.xml file that contained all of my detected devices.  Between that and a spec I found online I deduced the set_config_parameter invocation I needed to do.  Sort of.  I also had to read stack traces out of .homeassistant/home-assistant.log and do some more Googling to realize that where the docs indicated it wanted a numerical value the API actually expected what you would find in the “label” field of the ZWCFG XML.  What ultimately worked follows:

2017-11-26-174602_1824x984_scrot

The last gotcha stems from the Door/Window Sensor being a battery operated sensor as opposed to hard-wired.  This means that it spends most of its time sleeping to conserve power, waking up only when either the magnetic field changes or a scheduled time arrives.  To sync a new config immediately you’ll need to press the button on the sensor which causes it to wake immediately and perform tasks that otherwise would have waited until the next scheduled time.

The effort required to figure this out was frustrating but I was sufficiently successful this weekend that I will carry on.  I imagine acquiring a few more of each of the two sensor types and maybe some of the power flow control devices.  The next most obvious steps are to establish some triggering rules and to figure out exporting data to an off-prem cloud environment for back-up and analysis.  Oh, and I guess also playing around with the FOSCAM wireless IP camera I got, whose configuration I never reached due to bogging down on other things.

To Be Continued…

Building The Foundations Of Oppression

From the Financial Times…

The UK, France and Italy have promised to hold technology companies to account if they fail to block online terrorist or extremist content, with Emmanuel Macron, the French president, promising to “name and shame” companies that do not take robust action.

The meeting came after Mrs May and Donald Trump, the US president, discussed the need for internet companies to behave in a socially responsible way, move quickly to remove terrorist material and to stop it from appearing in the first place.

Mrs May challenged the internet companies to develop technology that would stop “evil material” appearing on the web or remove it within two hours of it appearing online. “Industry needs to go further and faster in automating the detection and removal of terrorist content online, and developing technological solutions which prevent it being uploaded in the first place,” she said.

Would this look any different, in shape if not actual configuration, from the machinery already used by totalitarian regimes to deploy pervasive and aggressive thought police against their own populations to prune “undesirable” content from the Internet?  Why should we trust all future leaders who would inherit such capabilities to use it responsibly?  How do we define what constitutes responsible use?  Why should we even trust today’s leaders when in the US they make a regular thing of demanding “apologies” for perceived insults and suppressing thought by not just butchering the funding for basic scientific research at government agencies but also redacting and possibly even destroying official records that do not fit their agenda?

If cynical realpolitik rooted in a desire to look tough on terrorism is not the base motivation, or maybe an actual desire to take things in a totalitarian direction, then heading down this path is a horrifying exercise in double-think and failure to consider secondary and tertiary effects.  The EU is certainly trying to have it both ways, on the one hand hammering Google and FaceBook for wielding their monopoly powers to unfair commercial advantage, and on the other hand demanding that they weaponize their Internet gateway status on behalf of the government.

Or maybe this isn’t double-think at all.  The most terrifying explanation is that governments are entering a negotiation with these tech behemoths with the idea of sanctioning their exploitation of their monopolies for commercial purposes if only they will consent to having their filtering powers bent to government will, a Faustian bargain if ever there were one.

God save us from a world where skynet is “automating the detection and removal of terrorist content online” and “prevent[ing] it [from] being uploaded in the first place”.  Could that possibly read more creepily?  How much ignorance of history, technology, and current events does it take to suggest such a thing seriously?  Or do they know exactly how this will end?

Deflection, Ideology, and Disaster: The Worst Of All Worlds

With the epic Hurricane Irma meting out destruction in Florida, Texans only just beginning to unwind the damage of Harvey, the memory of Sandy still stinging for New Yorkers, and Katrina a shameful blight on our recent history, the world is actively pressure testing our social contracts in ways that illustrate serious rifts at best and magical thinking at worst.

Meanwhile, there exists a natural temptation to broach climate change matters in the wake of a natural disaster such as Irma, but the reality is that exploring such a complex topic in the context of a single story would be irresponsible, and is best left to a numerical analysis of trends across a statistically significant collection of data points.

And yet there is a confluence of several factors that should have us scared independent of the culpability of humans in climate change on our planet:

  1. population density, especially in vulnerable coastal areas, is way up
  2. the transportation infrastructure around population centers is taxed to its limits
  3. population centers cannot operate self-sufficiently beyond a trivial time period
  4. population centers depend on fragile infrastructure to satisfy their needs
  5. a shocking proportion of people living in the most vulnerable areas are uninsured
  6. the terraforming around population centers eliminates natural weather shielding
  7. tight political and market cycles make engineering for fault tolerance difficult

The consequences of these realities could not be more palpable than for those struggling to find gasoline, water, and lodging as they flee the affected areas via jammed roads.  And the commentary from various thought leaders staking out their positions could not be less helpful, with government officials lamenting the cruelty of price gouging within the local economies and market religionists saying that allowing market-based pricing is all that is required to best allocate scarce resources.  To be blunt, the former are deflecting responsibility, the latter are making context-unaware arguments, and neither are meaningfully engaging with the reality on the ground.

When a big box store leaves pricing structures untouched in the run-up to a natural disaster, it is not doing so altruistically.  Rather, it is prioritizing optics over all else, and as consequence we see footage of hoarders carrying cartloads of regular-priced bottled water out of the stores.  Some of these purchasers are just panicked end-consumers, likely buying more product than they strictly need, doing so at the expense of other end-consumers who will find empty shelves.  Others are opportunistic re-distributors engaged in arbitrage between the storefront and the ultimate consumers who will pay huge mark-ups after finding the stores picked clean.  Both cause churn and uncertainty during a demand shock and do nothing to synchronize the supply-side with the local population’s needs.  The demand signal does not make its way usefully upstream.

But the crux of the folly of those making market-based arguments could be summed up in the one word that they are ignoring: latency.  Free markets, judiciously managed, are a great way to equilibrate the needs of producers and consumers.  But that equilibrium takes time: time for the demand signal to reach producers and time for the goods to flow from where they are produced to where they are needed.  This reality is perhaps well suited to dealing with the aftermath of a disaster, where the dramatically inflated local rates for professionals in the construction industry can serve as a nationwide draw until the crisis resolves, convincing, say, a plumber from California to spend a year living in Texas, but less well suited to sorting out a situation where the difference between life and death may be measured in hours, every manner of infrastructure is already completely overwhelmed, and the last thing affected regions need is a poorly managed inflow of people and goods just as officials are desperately reconfiguring highways to be one-way out of the area.  Allowing prices to swing during a crisis might help with the rationing of existing local supplies, but in a way that can feel capricious and cruel, and that does nothing to ameliorate the root cause of the misery, a supply shortage.

The 2008 financial crisis taught us some really painful lessons about what it means for market players to be too big to fail in the realm of banking.  We ultimately concluded that we still mostly want market forces steering things but that we also want certain safeguards in place to prevent cascading failures from spiraling out of control.  So-called “stress tests” became part of the national discourse.  We perhaps ought be drawing similar conclusions pertaining to distribution networks around our preparedness for disasters in the physical realm, natural or man-made, because when the proverbial excrement hits the fan things will be happening way too fast if we have not prepared and tested, doing so with a thoughtful blend of market forces and government planning and validation.

Unfortunately, to the extent that there is currently any interaction between government and market entities on such matters, it is just to have the former threaten criminal prosecution around “price gouging” for which there is no clear definition, and the savvy players among the latter group to take a hands-off approach that catalyzes situational anarchy.  With a continuation of this approach in the face of increasingly extreme environmental conditions we can only expect worsening outcomes.

Acquiring resources quickly in an emergency can be fantastically expensive and dangerously unreliable.  Helicopters to send in relief ain’t cheap or highly available.  Preparing proactively for an emergency, meanwhile, is not without its costs, and entails less resourcing for fun things during sunny days, which requires a certain degree of discipline.  Locating warehouses full of critical supplies near population centers means ponying up for the use of scarce real estate and maintaining inventory every day as a form of insurance payment.  Somebody always has to pay.  The main questions are who and when which will ultimately govern how much.

The situation we’ve currently got is one in which politicians engage in grandstanding and face-saving, established wholesalers and retailers are by and large helpless or indifferent, opportunistic profiteers make a quick buck without improving the ecosystem, and the masses suffer.  By the time a case of water is going for $100 we have really screwed up.  We could do a lot better in future situations by taking a more proactive stance.

Imagine a public-private partnership that harnesses the strengths of each sector by doing  things like the following:

  1. incentivize private sector distributors to maintain larger warehousing and distribution footprints in the vicinity of disaster prone areas to absorb demand shocks
  2. incentivize disaster zone residents to leave their homes in a more proactive and orderly fashion to smooth the load shocks on transportation infrastructure
  3. perform regular stress tests that posit certain scenarios, query the present availability of resources, simulate the outcomes, and phase in performance penalties
  4. establish data anonymization and aggregation procedures that allow for the fusion of public and private data sets to both predict and manage the play-out of disasters
  5. begin pulling the levers that will require those who choose to live in high-risk areas to bear fuller costs for their decisions so as to encourage rational risk-taking, to include meaningfully enforced requirements on insurance that ultimately cause either changes in behavior or fair passing-along of costs

Consider one of the specific things that happens during mass exoduses from disaster areas, specifically that highway toll collection halts and traffic streams through unmonitored.  That’s pretty reasonable given the hand the government agencies have at the moment.  But imagine what we could do if over time we completely phased out the acceptance of cash tolls, had the corresponding expectation that every vehicle transiting a toll station could be tracked to an owner, and implemented some manner of “toll” that incentivized people to leave more proactively.  This wouldn’t necessarily be easy, because the people most likely to procrastinate are probably the ones least able to take time off from work, but with some cleverness it could be done, perhaps using a progressively-structured income-linked tax credit as well as emplacing laws that prevent retribution by employers against employees who take advantage of the arrangement.  The trade-off relative to having to perform expensive and risky rescue and relief operations in disaster areas would likely be worth it.

It is probably not particularly controversial to say that $100 cases of water in disaster zones is icky and heart-breaking.  Making sure that those kind of things are less likely to happen in the future is going to take some serious thinking, hard work, and proactive sacrifice.  Harsher times are coming.  For now, the system we’ve got is the system we’ve got, and people need help.